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?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
  1. Can you provide some examples of the IDs?
  2. Do they need to have sequential numbers, such as A001, A002, etc.?
 
Upvote 0
Yes, in sequential order is what I was hoping for, like B10001, B10002, B10003, etc.
 
Upvote 0
Can you show us the code which send data to the worksheet?
And the ID's are in col A?
Sorry, here it is the code that writes to the worksheet. The ID's don't have to be column A, but if you tell me there is good reason why the ID's should be in column A, then I can adjust my code. Currently, the ID's would be in column L, I just don't have that code written yet.

Private Sub cmdSave_Click()

'Validation
If Me.TextBox1.Value = "" Then
MsgBox "Please enter your first name", vbCritical
Me.TextBox1.SetFocus
Exit Sub
End If

If Me.TextBox2.Value = "" Then
MsgBox "Please enter your last name", vbCritical
Me.TextBox2.SetFocus
Exit Sub
End If

'Validation.
If Me.TextBox3.Value = "" Then
MsgBox "Please enter a valid e-mail address", vbCritical
Me.TextBox3.SetFocus
Exit Sub
End If

Dim emptyRow As Long

'Make Sheet1 active
Worksheets("Registration").Activate

'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

'Transfer information
Cells(emptyRow, 1).Value = TextBox1.Value
Cells(emptyRow, 2).Value = TextBox2.Value
Cells(emptyRow, 3).Value = TextBox3.Value
Cells(emptyRow, 4).Value = TextBox4.Value
Cells(emptyRow, 5).Value = TextBox5.Value
Cells(emptyRow, 6).Value = TextBox6.Value
Cells(emptyRow, 7).Value = TextBox7.Value
Cells(emptyRow, 8).Value = TextBox8.Value
Cells(emptyRow, 9).Value = TextBox9.Value
Cells(emptyRow, 10).Value = TextBox10.Value


End Sub
 
Upvote 0
Is it necessary for the ID to contain letters?
It would be more convenient if the ID consists only of numbers, such as 6 digits starting at 100001. This way, it will be simpler to identify the highest number in the data (column L) using the MAX function. The new ID would be the highest number + 1.
 
Upvote 0
It would not be required to have the ID start with a letter. I was using the letter to distinguish between multiple events and attendees in different counties. If I could begin the numbering for one county in 100001 and the second county with 200001 and the third county with 3000001, that would be great.
 
Upvote 0
Attendees should have an ID
What I mean was, what information/category do you want the ID to reflect?
For example: say the ID is like this: BF001
What is B, the first letter, means? it could mean a city where B means New York.
What is F, the second letter, means? it could mean gender where F means female.
Therefore, you need to construct the ID pattern based on the specific information you want to include.
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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