generate a random unique ID?

cloobless

Board Regular
Joined
Jul 15, 2014
Messages
84
Office Version
  1. 2010
Platform
  1. Windows
Hi, there.
Is there a way to generate a unique ID in for a row based on some adjacent cells?

1. If the row is unique from any other row, it gets a unique ID. What would make it unique is if just one of the cells' values is different from another row.
2. If the end of row doesn't yet have an ID (e.g. is newly added), it will get one (button press?).
3. New rows would get added all the time. It's very unlikely that a new row would have an exact match to a previous row.

[TABLE="class: grid, width: 700"]
<tbody>[TR]
[TD]dateshipped[/TD]
[TD]datereceived[/TD]
[TD]palletname[/TD]
[TD]itemname[/TD]
[TD]uniqueID[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12/1/2017[/TD]
[TD]12/1/2018[/TD]
[TD]CITRUS[/TD]
[TD]ORANGE[/TD]
[TD]aba124[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12/1/2017[/TD]
[TD]12/1/2018[/TD]
[TD]CITRUS[/TD]
[TD]LIME[/TD]
[TD]ggh392[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/1/2018[/TD]
[TD]4/1/2018[/TD]
[TD]VEGGIES[/TD]
[TD]CUCUMBER[/TD]
[TD]hhf356[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2/1/2018[/TD]
[TD]4/1/2018[/TD]
[TD]VEGGIES[/TD]
[TD]LIME[/TD]
[TD](generate)[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I looked through the "random" function but have no idea of how to apply it here. Any ideas?
Thank you.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try this

Code:
Sub generate_ID()
    lr = Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To lr
        If Cells(i, "E") = "" Then
            wcount = WorksheetFunction.CountIfs( _
                Range("A2:A" & lr), Cells(i, "A"), _
                Range("B2:B" & lr), Cells(i, "B"), _
                Range("C2:C" & lr), Cells(i, "C"), _
                Range("D2:D" & lr), Cells(i, "D"))
            If wcount = 1 Then
                'generete id
                For j = 1 To 3
                    a = WorksheetFunction.RandBetween(1, 26) + 96
                    cad = cad & Chr(a)
                Next
                For j = 1 To 3
                    a = WorksheetFunction.RandBetween(1, 10) + 47
                    cad = cad & Chr(a)
                Next
                Cells(i, "E").Value = cad
            End If
        End If
    Next


    MsgBox "Done"
End Sub
 
Upvote 0
Hello, Dante. This works superbly. I am very thankful that you were willing to share your time and expertise to help me solve this problem. Thank you, kindly. Best.
 
Upvote 0
im glad to help you, thanks for your kind comments.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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