davehill1974
Technical User
Hi everyone,
I have been trying repeatedly for days now to write a macro to generate random numbers. I need to generate 23 unique numbers in 5 columns. I have found a macro that can do one column at a time but i cannot modify this to work over the five columns.
Here is the code for you to look at:
Sub CreateRand()
Dim Nums(23)
Dim I As Integer
Dim X As Integer
Dim rng As Range
Dim c As Range
Dim Filled As Boolean
For I = 1 To 23
Nums(I) = I
Next I
Set rng = Range("f1:f23")
For Each c In rng
Do
X = Int((Rnd * 23) + 1)
If Nums(X) <> 0 Then
c.Value = Nums(X)
Nums(X) = 0
Filled = True
End If
Loop Until Filled
Filled = False
Next c
End Sub
All help will be greatly received!!!!!!
Thanks, a slowly going bald Excel user.
I have been trying repeatedly for days now to write a macro to generate random numbers. I need to generate 23 unique numbers in 5 columns. I have found a macro that can do one column at a time but i cannot modify this to work over the five columns.
Here is the code for you to look at:
Sub CreateRand()
Dim Nums(23)
Dim I As Integer
Dim X As Integer
Dim rng As Range
Dim c As Range
Dim Filled As Boolean
For I = 1 To 23
Nums(I) = I
Next I
Set rng = Range("f1:f23")
For Each c In rng
Do
X = Int((Rnd * 23) + 1)
If Nums(X) <> 0 Then
c.Value = Nums(X)
Nums(X) = 0
Filled = True
End If
Loop Until Filled
Filled = False
Next c
End Sub
All help will be greatly received!!!!!!
Thanks, a slowly going bald Excel user.