Excel vba increment unique id for each row

Jaye Cavallo

New Member
Joined
Mar 10, 2022
Messages
45
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am seeking an Excel VBA method to create a unique ID for every row of data that is entered by an attendee to an event. I have the userform designed and the data from the form is passed on to the worksheet as expected. Is there a way to create a unique id every time an attendee enter his information and the data is saved to the work sheet?
 
There are three events, one in each county. B for one county, C for the second county and F for the third county. So each event in each county would represent an attendee with not only a unique number, but also a number that would show the county for which they are from, thus the letter. For the first event, the ID would B000000. The second event would be C000000. The third event would be F000000. So, one Excel file to register attendees at the first event, the second file for the second event, and a third file for the third event, just revising the VBA code to reflect the letter change in the ID and increment the number by one for each attendee.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Ok, I will try to write the code in few hours when I have time.
When you update data via the userform, will the last cell with data in column L always have the highest number ID?
If so, the code can generate a new ID just by adding 1 to the number ID in the last cell.
 
Upvote 0
Yes when the data is added the column L will increment by 1
Try this:
In your code, add the blue lines before the End Sub
Rich (BB code):
Cells(emptyRow, 9).Value = TextBox9.Value
Cells(emptyRow, 10).Value = TextBox10.Value

'ID pattern "?000001" 'a letter followed by 6 digits.
With Cells(emptyRow, "L")
    .Value = Left(.Offset(-1), 1) & Format(Mid(.Offset(-1), 2) + 1, "000000")
End With

End Sub

In order to make it work you need to have at least 1 row of data (say in row 2) and manually insert the ID, such as B000001
Jaye Cavallo - Excel vba increment unique id for each row #1.xlsm
KL
1somethingID
2qwertB000001
3
Sheet1

Basically, the code will find the last cell with data in col L (i.e the last ID) and then insert a new ID below it. The ID pattern must be a letter followed by 6 digits.
 
Upvote 0
Solution
Thank you for your solution. The code works a you suggested. Now I will be pushing the envelop. In my next post, I will ask if it is possible to print a name tag from this userform.
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top