I have this vba to generate random numbers 0-9..my problem is that it will generate in a column and I would like it to also generate random numbers in the row .
any help would be greatly appreciated.
Sub GetRandomNumbers()
Const intLowest As Integer = 0 'Lowest number required
Const intHighest As Integer = 9 'Highest number required
Const intHowMany As Integer = 10 'Number of different values to return
Dim booFlag As Boolean
'Check to prevent infinite loop
If intHowMany > (intHighest - intLowest + 1) Then
MsgBox "Too many numbers or too small a range."
Exit Sub
End If
'Set up array to hold the random value
Dim arrRandom(1 To intHowMany) As Integer
Randomize 'Resets random seed
'Generate the first random value
arrRandom(1) = Int((intHighest + 1 - intLowest) * Rnd) + intLowest
'Generate subsequent random values and ensure no dupes
For i = 2 To intHowMany
Do
booFlag = False
arrRandom(i) = Int((intHighest + 1 - intLowest) * Rnd) + intLowest
For j = 1 To i - 1
If arrRandom(j) = arrRandom(i) Then booFlag = True
Next j
Loop Until booFlag = False 'Ensures value not kept if it is a dupe
Next i
'Write the values back to the worksheet - change "B4" reference as required
For i = 1 To intHowMany
Range("b4").Offset(i, 0).Value = arrRandom(i)
Next i
End Sub
Bookmarks