LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Populating a select group of cells with randomized names...

Hello,

I need some help changing my code below that populates a 10x10 table with
random names (including Null values) to equal 100 names from a range of
names in Column O to a select group of cells that equals 64. For example,
if there were 4 names then each name should appear in those cells 16
times. Conversely, if there were 5 names, each name should appear exactly
12 times with 4 Nulls appearing randomly as well.

Here is the subroutine that correctly populates the 10x10 table:

Sub popTable()
Columns("O").Select
borRow = Selection.Find(What:="Name", After:=activeCell,
LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True).row
eorRow = Selection.Find(What:="Null", After:=activeCell,
LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True).row
Range("O" & borRow + 1 & ":O" & eorRow - 1).Sort Key1:=Range("O" &
borRow), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Set vNames = Range("O" & borRow + 1 & ":O" & eorRow -
1).SpecialCells(xlCellTypeConstants)
numNames = vNames.Count
countNames = Int(100 / numNames)
ReDim vArr(1 To 100)
For i = 0 To numNames - 1
For j = 1 To countNames
vArr(i * countNames + j) = vNames(i + 1)
Next j
Next i
For i = 100 To 2 Step -1
randNum = Int(Rnd() * 100) + 1
tempValue = vArr(i)
vArr(i) = vArr(randNum)
vArr(randNum) = tempValue
Next i
ReDim vResult(1 To 10, 1 To 10)
For i = 1 To 10
For j = 1 To 10
vResult(i, j) = vArr((i - 1) * 10 + j)
Next j
Next i
Range("D4:M13").Value = vResult
For i = 4 To 13
For j = 4 To 13
If Cells(i, j).Value = "" Then
Cells(i, j).Value = "Null"
End If
Next j
Next i
End Sub

Instead of filling the 10x10 array:

Range("D4:M13").Value = vResult

I need to populate the following 64 cells using VBA with the same logic,
however, I am having troubles getting this to work:

Range("B3,B4,B6,B7,B9,B10,B12,B13,B15,B16,B18,B19, B21,B22,B24,B25,B27,B28,B30,B31,B33,B34,B36,B37,B3 9,"
& _
"B40,B42,B43,B45,B46,B48,B49,V3,V4,V6,V7,V9,V10,V1 2,V13,V15,V16,V18,V19,V21,V22,V24,V25,V27,V28,V30, V31,"
& _
"V33,V34,V36,V37,V39,V40,V42,V43,V45,V46,V48,V49") .Value = vResult

I appreciate any help in getting this written correctly.

Thanks much,

Kevin

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating listbox with sheet names johnb Excel Discussion (Misc queries) 1 May 16th 08 12:33 PM
Randomized Functions Kleverton Silva Excel Discussion (Misc queries) 7 November 16th 05 06:49 PM
Haw to Randomized available data Adda Excel Worksheet Functions 2 April 10th 05 09:57 PM
VBA for opening file/populating combo box with sheet names Sinobato[_4_] Excel Programming 3 July 26th 04 06:35 PM
Populating sheet names in combobox Todd Huttenstine[_2_] Excel Programming 3 December 21st 03 12:11 AM


All times are GMT +1. The time now is 10:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"