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.

dateshippeddatereceivedpalletnameitemnameuniqueID
12/1/201712/1/2018CITRUSORANGEaba124
12/1/201712/1/2018CITRUSLIMEggh392
2/1/20184/1/2018VEGGIESCUCUMBERhhf356
2/1/20184/1/2018VEGGIESLIME(generate)

<tbody>
</tbody>

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

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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