I am using code from J.E. McGimpsey's site, which works great. I have a problem with the code starting on the wrong line, but cannot figure out how to correct it. This is the table before the code is run:
column A colum B
Name Random Number Assignment
Janet
Janet
Mark
Sam
Sam
Sam
Tabel after code is run: The title in column B gets overwritten with a random number and the last row is blank
column A colum B
Name 3
Janet 6
Janet 2
Mark 8
Sam 7
Sam 4
Sam
This is the code:
Sub RandomNumber()
Dim Lowest As Long
Dim Highest As Long
Dim x As Long
Dim y As Long
Dim Total As Long
Dim ChoiceTemp As Long
Dim Choice() As Long
Dim Repeat As Boolean
Application.ScreenUpdating = False
Lowest = 1
Highest = InputBox("what is the highest number?")
Total = InputBox("How many combinations do you want")
ReDim Choice(1 To Total)
For x = 1 To Total
a:
Randomize
Repeat = False
ChoiceTemp = Int((Highest + 1 - Lowest) * Rnd + Lowest)
For y = 1 To Total
If Choice = ChoiceTemp Then
Repeat = True
Else
End If
Next y
If Repeat = True Then
GoTo a:
Else
Choice(x) = ChoiceTemp
End If
Next x
For x = 1 To Total
Sheets("Sheet1").Range("B" & x).Value = Choice(x)
Next
End Sub
column A colum B
Name Random Number Assignment
Janet
Janet
Mark
Sam
Sam
Sam
Tabel after code is run: The title in column B gets overwritten with a random number and the last row is blank
column A colum B
Name 3
Janet 6
Janet 2
Mark 8
Sam 7
Sam 4
Sam
This is the code:
Sub RandomNumber()
Dim Lowest As Long
Dim Highest As Long
Dim x As Long
Dim y As Long
Dim Total As Long
Dim ChoiceTemp As Long
Dim Choice() As Long
Dim Repeat As Boolean
Application.ScreenUpdating = False
Lowest = 1
Highest = InputBox("what is the highest number?")
Total = InputBox("How many combinations do you want")
ReDim Choice(1 To Total)
For x = 1 To Total
a:
Randomize
Repeat = False
ChoiceTemp = Int((Highest + 1 - Lowest) * Rnd + Lowest)
For y = 1 To Total
If Choice = ChoiceTemp Then
Repeat = True
Else
End If
Next y
If Repeat = True Then
GoTo a:
Else
Choice(x) = ChoiceTemp
End If
Next x
For x = 1 To Total
Sheets("Sheet1").Range("B" & x).Value = Choice(x)
Next
End Sub