Closed Thread
Results 1 to 8 of 8

Excel 2007 : VBA Help Needed to Create a Macro to create a Unique Number...

Hybrid View

  1. #1
    Registered User
    Join Date
    10-25-2011
    Location
    Des Moines, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    18

    Question VBA Help Needed to Create a Macro to create a Unique Number...

    I have little VBA background and need to write a macro that will create a unique number for every row in an Excel 2007 worksheet. This worksheet has over 5000 rows in it. The problem I am having with it now is that it has been sorting a column (archive index #) based upon the numerical/text order when it shouldn't be sorting it at all.

    A column has been added (system ID) to have a macro generate a unique number to each row of information. New rows will be inserted into this worksheet from any point not just to the bottom. After a new row is added the macro would be ran to generate new unique numbers. Is it possible to do this??

    The unique number (system ID) does not have to stay the same, just the order the rows appear originally after a new row is added.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: VBA Help Needed to Create a Macro to create a Unique Number...

    The workbook you attached has no code in it, so I'm not sure how it's getting sorted. Are you doing this manually, or is there code behind the sort? Also, I need a bit of information about what kind of format you need the system ID to have. Is it pure numeric? Do you want alpha characters as well? How many digits? Same number of digits every time?
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    10-25-2011
    Location
    Des Moines, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: VBA Help Needed to Create a Macro to create a Unique Number...

    This is being manually sorted. There is no code in this, correct. The format for the System ID is purely numerical.. preferrably sequential.

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: VBA Help Needed to Create a Macro to create a Unique Number...

    The code in the attached workbook will generate a new ID number based on the greatest value it finds in the D column. If you are inserting a single ID number, position your cursor in the blank cell where you want to place the ID number, and run the macro NewID. If you want to generate more than one, select the cells in which you want to place the ID. CAUTION! This will place an incremented number in EVERY cell you select, so only select cells in the D column. As for your sorting issue, I still need more information. What column are you sorting by, and what other levels of sort are you applying?
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-25-2011
    Location
    Des Moines, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    18

    Smile Re: VBA Help Needed to Create a Macro to create a Unique Number...

    tlafferty.... Thank you for your kind assistance with this question. Let me clarify a little bit. The code would need to recognize the last row with data in it and start from cell D2. The sorting is done by filters in the header row. Please see attached workbook for reference.

    Thanks again for all of your help with this. It is greatly appreciated.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-25-2011
    Location
    Des Moines, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: VBA Help Needed to Create a Macro to create a Unique Number...

    With the above forgot to mention... with it recognizing the last row with data, that would alleviate the need to manually highlight the entire column considering it could have 16000+ rows of data. Thanks.

  7. #7
    Registered User
    Join Date
    05-16-2012
    Location
    Utah
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: VBA Help Needed to Create a Macro to create a Unique Number...

    So Lafferty, How could I take this code for unique numbers and search sheet "forecast" to find the next unique number and in the range "A3:A2000" and return the new unique id to a textbox in a userform as the userform initializes?

    does that make sense? I want a userform's textbox (on initialize) to check sheet "Forecast" and create a new unique id that is returned to textbox_UniqueID in the form.

    Thanks in advance!
    Last edited by bg_enigma1; 05-16-2012 at 05:02 PM.

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA Help Needed to Create a Macro to create a Unique Number...

    bg_enigma1,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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