Stephen_IV
Well-known Member
- Joined
- Mar 17, 2003
- Messages
- 1,168
- Office Version
- 365
- 2019
- Platform
- Windows
In column B I have 5 Digit Unique Random Numbers that were pre-assigned. I use the code below that makes 5 Digit Unique Random Numbers. The problem is that since I already have pre-assigned ID numbers in column B is there a way to adapt to this code to Look at Column B and add those numbers into the Unique random digits so that I could have a unique list generated in column A minus those numbers already assigned in column B.
Thanks In Advance Stephen
Sub PINCreate()
Dim RndNo As Long
Dim Test As Long
Dim i As Long
For i = 2 To 5500
Randomize
Do
RndNo = Int((99999 - 10000 + 1) * Rnd + 10000)
On Error Resume Next
Test = Application.Match(RndNo, Range(Cells(1, 1), Cells(i, 1)), 0)
If Err.Number = 13 Then
GoTo FoundUnique
Err.Clear
End If
Loop
FoundUnique:
Cells(i, 1) = RndNo
Next i
End Sub
Thanks In Advance Stephen
Sub PINCreate()
Dim RndNo As Long
Dim Test As Long
Dim i As Long
For i = 2 To 5500
Randomize
Do
RndNo = Int((99999 - 10000 + 1) * Rnd + 10000)
On Error Resume Next
Test = Application.Match(RndNo, Range(Cells(1, 1), Cells(i, 1)), 0)
If Err.Number = 13 Then
GoTo FoundUnique
Err.Clear
End If
Loop
FoundUnique:
Cells(i, 1) = RndNo
Next i
End Sub