+ Reply to Thread
Results 1 to 14 of 14

Macro stops working on row

  1. #1
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Exclamation Macro stops working on row

    Please look at the attached sheet. I got some help in this forum earlier (http://www.excelforum.com/excel-prog...-column-c.html) and the code i got worked at first, but when i changed the sheet (added columns) and attempted to alter the code accordingly, now the code stops working at line 222.

    I can't tell anything different about the data on lines 223 and so forth that would cause the macro to stop running there, maybe someone with more experience will notice?


    Sheet1 is the original data. Sheet2 is after the code has been run. The item descriptions have been removed.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by smokebreak; 01-22-2010 at 06:00 PM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: macro inexplicably stops working on row 225

    I ran your macro and it is not stopping at row 221. There are only 221 entries that are being extracted. The two filter lines
    Please Login or Register  to view this content.
    are restricting the number of entries that you are extracting. Are you sure that these two tests are correct for what you want to do?

  3. #3
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: macro inexplicably stops working on row 225

    Quote Originally Posted by blane245 View Post
    The two filter lines ...are restricting the number of entries that you are extracting. Are you sure that these two tests are correct for what you want to do?
    Unfortunately I barely can read VBA code, so I'm not really sure, I got this code from someone else on this board and I do not fully understand it. Perhaps could you explain what it means, or better yet, help me fix it to do what I want it to do?

    Going back to my original post, the problem I am trying to solve is that in the raw data, there are often several lines for a unique order number/line number combination. for each Order number/line number combination, I only want to pull out the first time that "Next Stat" = 530 and the first time "Next Stat"=540. Everything else can be deleted.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    The code is designed to only copy unique values from sheet to the other. Currently, there are only 221 unique entries on "Sheet1".
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    Quote Originally Posted by Leith Ross View Post
    Hello smokebreak,

    The code is designed to only copy unique values from sheet to the other. Currently, there are only 221 unique entries on "Sheet1".
    Should I re-open my original question then, or should I pursue the issue in this thread? My original post is here:
    http://www.excelforum.com/excel-prog...-column-c.html

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    Don't start another thread. Leave this one open. What is the macro not doing now that it seemed to be doing before (since you marked the previous post solved)?

  7. #7
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    The macro has ceased going through all the data in the set. my original data was a lot like the sample on my first post. I added the columns and then found that the macro no longer did what I needed it to do. Still not sure what I did wrong, since all I did was change the column numbers in the script. All I need it to do is sort through each order/line combination for the first instances of "Next Stat"=530 and =540.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    I will look over the code again, but from what you have posted and what the code does, 221 seems to me to be correct. How many matches do you expect there to be in the sample workbook?

  9. #9
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    Quote Originally Posted by Leith Ross View Post
    Hello smokebreak,

    How many matches do you expect there to be in the sample workbook?
    The code must be wrong in ways I do not pretend to understand.... If you add a column to concatenate columns B and D (Order and Line), then subtotal those results to count unique values, there are 469 unique order/line combinations. Each combination should have 2 lines (one where next = 530, one where next = 540). Some will only have one line (if there is no entry for status 530 or 540 on that order line). So there should be about 930 lines in the total output.

    Thank you for your help on this, I hope you are not as frustrated as I am LOL
    Last edited by smokebreak; 01-22-2010 at 09:51 AM. Reason: to show how i got 469

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    Thanks for the update. I understand now what you want to do and why the code currently is producing only 221 results. I'll rewrite the macro and test it using the data in the workbook you posted. I should get about 930 matches in that workbook, correct?

  11. #11
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    oh my, please accept my apology:
    I posted a "stripped down" solution to the problem which may or may not help you, but almost certainly doesn't warrant two threads:

    http://www.excelforum.com/excel-prog...ml#post2238910

    The idea is basically to have the macro add a column to concatenate order number, line number, and next stat. (may also have to reformat the line number to include a leading zero). Then loop through the concatenated data and find the first instances of the last 3 digits being appropriate to what I'm looking for... once the rows are deleted, the concatenated column could be removed also. I think it will work that way but don't want to derail your solution if you are working on something more elegant.

    As a mod please delete that other thread if it is inappropriate. I didn't see your reply until just now.

    *shame*

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Macro stops working on row

    Hello smokebreak,

    This macro produces 929 results, on a PC. There were 2 basic problems. First column "B" was being used instead of column "C" and secondly, the "Next Stat" column contains both numbers and text representing numbers. The macro shown below has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    12-15-2009
    Location
    Houston, TX, USA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Macro stops working on row

    FINALLY a solution that works. Thank you for your persistence to help a stranger, Leith.

  14. #14
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Macro stops working on row

    another way with a Collection
    Please Login or Register  to view this content.
    But alas the data has changes since the origonal closed post
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1