generating non-repeating random numbers in a range

G

Guest

I'm trying to generate numbers for bingo cards - each row as 1 card - columns
A-E for the "B" numbers, columns F-J for the "I" numbers and so forth. How
do I get the numbers for each Bingo letter -"B", "I" not to repeat?
 
T

Tom Ogilvy

generate the numbers you need, then "shuffle" them, then pick as many as you
need. Here is a shuffle routine you can incorporate.

Sub Shuffle()
'
' Algorithm from:
' The Art of Computer Programming: _
' SemiNumerical Algorithms Vol 2, 2nd Ed.
' Donald Knuth
' p. 139 [Algorithm P]
'
'
Dim list As Variant
Dim rng As Range
Dim t As Long, j As Long, k As Long
t = 100
Set rng = Range(Cells(1, 1), Cells(1, 1).End(xlDown))
list = rng.Value
t = UBound(list, 1)
j = t
Randomize
For i = 1 To t
k = Rnd() * j + 1
lngTemp = list(j, 1)
list(j, 1) = list(k, 1)
list(k, 1) = lngTemp
j = j - 1
Next
rng.Value = list
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top