Auto Generate Unique ID

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good day,

I'm trying to set up a sheet so it will generate a unique ID for that entry in column P when new information is added to the A column. I've tried a couple of formulas but can't get anything to work correctly so I'm thinking it needs to be VBA but I'm not sure where to begin. Any help with this would be great, the only thing I've found that I think I need is the following:

VBA Code:
Dim maxNumber
    maxNumber = Application.WorksheetFunction.max(Range("P:P"))
    Target.Offset(0, -1) = maxNumber + 1
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet.
Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing'
and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet.
Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing'
and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
The problem is that its sensitive data I don't feel comfortable sharing, so that's why I was quite vague. It would be too much effort to de-sensitize it to be worthwhile.
 
Upvote 0
I wouldn't need all the data. A dozen or so rows would be enough.
 
Upvote 0
I wouldn't need all the data. A dozen or so rows would be enough.
Here is a very rough sample. When a new row is added to the table, I want a feedback ID generated in column E that's unique to that entry and doesn't change when the table is sorted.
sample.xlsx
ABCDEFGHI
1customernameemailfeedbackfeedback ID
2ajohnn/amisc 1
3bmaryn/a2
4c sallyn/a3
5edaven/a4
6fbradn/a5
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Sheet1
 
Upvote 0
The sample you posted doesn't show any data. It shows only cell E7.
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Start entering your data in column A.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    Target.Offset(, 4) = Application.WorksheetFunction.Max(Range("E:E")) + 1
End Sub
 
Upvote 0
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Start entering your data in column A.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    Target.Offset(, 4) = Application.WorksheetFunction.Max(Range("E:E")) + 1
End Sub
Thanks, this works for manual entry but what if the data is copied from another location and then pasted in the A column? It doesn't update during that, sadly.
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A:A")) Is Nothing Then Exit Sub
    Target.Offset(, 4).Resize(, 1) = Application.WorksheetFunction.Max(Range("E:E")) + 1
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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