View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bill Kuunders Bill Kuunders is offline
external usenet poster
 
Posts: 303
Default Need to randomly populate a 10x10 array of cells with 100 names - 5 people listed 20 times each...

Got a bit of a mix. Mostly macro, but I use the randbetween formula to get
a random selection. And I populate column D first
This list is then picked up in the area E2 to N11

the macro .....................

Sub populate5twenty()
Dim counter
Dim tom
Dim sue
Dim ray
Dim lin
Dim bob

' Macro recorded 8/02/2004 by Bill

Start:

Calculate 'to randomly select the next
name
If counter = 100 Then Exit Sub 'after 100 names pasted stop

If Range("b1") = 1 And tom = 20 Then GoTo Start 'range b1 has formula
=randbetween(1,5)
If Range("b1") = 2 And sue = 20 Then GoTo Start 'if we had twenty try again
If Range("b1") = 3 And ray = 20 Then GoTo Start
If Range("b1") = 4 And lin = 20 Then GoTo Start
If Range("b1") = 5 And bob = 20 Then GoTo Start


If Range("b1") = 1 Then tom = tom + 1 'add one to counter for tom
If Range("b1") = 2 Then sue = sue + 1
If Range("b1") = 3 Then ray = ray + 1
If Range("b1") = 4 Then lin = lin + 1
If Range("b1") = 5 Then bob = bob + 1

counter = counter + 1


Range("C1").Select 'range c1 has formula to convert
number 1 to 5 into names
Selection.Copy
Range("D1").Select
ActiveCell.Offset(counter, 0).Activate 'go down one row in column D
before pasting the next name

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False


GoTo Start
End Sub
"Kevin Lyons" wrote in message
m...
Hello,

I need to randomly populate a 10x10 array of cells with 100 names - 5
people listed 20 times each {Tom, Sue, Ray, Lin, Bob}.

For example, in the range, C3:L12, I need Tom listed exactly 20 times,
Sue listed 20 times, etc.

A VBA solution is the preferred method!

Thanks,

Kevin