+ Reply to Thread
Results 1 to 11 of 11

Fill sequential number down empty column, save last number, use as first number next time

  1. #1
    Registered User
    Join Date
    10-16-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 365
    Posts
    13

    Fill sequential number down empty column, save last number, use as first number next time

    New poster to forum. Hope I am doing this correctly. Thanks for all the help you have been in the past without me posting!

    I have a macro, inserted below, attributed to Harald Staff, that reads a text file for the last incremental number, and then fills B5 with the next number, and updates the text file. Works great, but it currently only fills one cell (B5).

    I need it to fill all the empty rows down column B, and then save that last number. The number of rows that need to be numbered changes from use to use. There is always data in column A and column C. Column B is always empty before the macro runs.

    I am afraid it is beyond me to get it to determine the last row (last data in Column A or C) and to get it to fill B5 down to the last row with an incremental number, starting at the saved number plus one, and then store the last number in the text file for future reference.

    Thanks in advance for any help you can provide.

    Bob

    Here is the current code:

    Please Login or Register  to view this content.
    You almost have the code tags correct the last 1 needs to be [/code
    Last edited by FDibbins; 10-25-2013 at 03:44 PM.

  2. #2
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Fill sequential number down empty column, save last number, use as first number next t

    You can get the last row in a column by using this formula. Change the "A1" to the column you want the last row for.
    Please Login or Register  to view this content.
    To fill to the last row, you can use something like this. LastRow below would be the larger of last row for A or C
    Please Login or Register  to view this content.
    Hope this helps

  3. #3
    Registered User
    Join Date
    10-16-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Fill sequential number down empty column, save last number, use as first number next t

    Thanks, I see what how that works. However, I am afraid I don't see how to add it to the original code to make the original code fill the sequential number to the end, and then save the last sequential number? I guess there is only so far "Google University" can take you in programming

  4. #4
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Fill sequential number down empty column, save last number, use as first number next t

    I'm not sure of the results of your original code, however I think that this is what the code should look like
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-16-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Fill sequential number down empty column, save last number, use as first number next t

    Thanks for the extra work! Unfortunately, I can't get it to work. Maybe the files will help. I attach five files here for your review.

    1. Source.xlsm
    2. LeadNumberMaster.txt
    3. Three output files parsed out and saved by Client name and data.

    As you can see the Numbering macro does increment and number the first line of data, but not all the lines of data.

    The Parse macro does extract data by Client and save the files.

    I hope these help. You may want adjust paths for files before trying them.

    Thank you for your response, experties and assistance!

    Bob
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Fill sequential number down empty column, save last number, use as first number next t

    So you want column B in Source.xlsm incremented? When, before or after, the split?
    Which macro gets executed first? Sub Lead_Number() or Sub Parse_Dealer_Files()?

  7. #7
    Registered User
    Join Date
    10-16-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Fill sequential number down empty column, save last number, use as first number next t

    Quote Originally Posted by hectop View Post
    So you want column B in Source.xlsm incremented? When, before or after, the split?
    Which macro gets executed first? Sub Lead_Number() or Sub Parse_Dealer_Files()?
    Thanks for the response. Sorry I was traveling and away from email.

    Filling the incremental number sequence would occur first.

    I usually write them as separate macros and then call them in the order I want from a main macro. It seems easier to me to maintain and test individual macros than one huge one.

    But either way is fine!

    Thanks again for filling in for my lack of knowledge.
    Bob

  8. #8
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Fill sequential number down empty column, save last number, use as first number next t

    This should do it.
    Source.xlsm

  9. #9
    Registered User
    Join Date
    10-16-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 365
    Posts
    13

    Re: Fill sequential number down empty column, save last number, use as first number next t

    Quote Originally Posted by hectop View Post
    This should do it.
    Attachment 274378
    Thank you so much. It works like a charm ...... until about 32809
    at which time it throws off a "stack overflow" error. I don't see a reason for it to care that the number gets that big?

    Any ideas?

    Thanks again for all the help!

    Bob

  10. #10
    Forum Contributor
    Join Date
    09-30-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2007
    Posts
    229

    Re: Fill sequential number down empty column, save last number, use as first number next t

    Maximum integer range is -32,768 to 32,767.
    Change the line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    This converts it a Long variable which has a range of -2,147,483,648 to 2,147,483,647.

  11. #11
    Registered User
    Join Date
    10-16-2013
    Location
    Charlotte, NC
    MS-Off Ver
    Office 365
    Posts
    13

    Thumbs up Re: Fill sequential number down empty column, save last number, use as first number next t

    As they used to say in Chicago... "You da Man!". Works perfectly. Thanks so much for getting that working for me.
    Bob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need macro that will update a sequential number field each time I print a form
    By eradline in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2012, 05:55 PM
  2. Lookup largest number in a column treating negative number as postive number
    By xWiZardx in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-17-2010, 08:09 AM
  3. How do I generate a sequential serial number every time I tab to a new line?
    By asbo604 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2009, 05:17 AM
  4. Replies: 7
    Last Post: 12-18-2008, 07:34 PM
  5. Replies: 2
    Last Post: 08-06-2008, 05:18 AM

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