Hi guys,
Sorry to bother you, I have been looking at this line of code for a few hours now and
I can't seem to get why one code is giving a correct solution and the other one
not even close. They are both identical but there are some difference.
Just wondering if anyone could see why that is?
The program is suppose to pick up about 11 cell values, it then store these
cell values into a collection, and randomly picking out the 11 values without repeating
until there is no more to pick out.
Here is the code: (the top one doesn't give the correct result, it picks it out of the same ones and
the number doesn't seem to store correctly, the bottom codes works as it suppose to work.)
Sorry to bother you, I have been looking at this line of code for a few hours now and
I can't seem to get why one code is giving a correct solution and the other one
not even close. They are both identical but there are some difference.
Just wondering if anyone could see why that is?
The program is suppose to pick up about 11 cell values, it then store these
cell values into a collection, and randomly picking out the 11 values without repeating
until there is no more to pick out.
Here is the code: (the top one doesn't give the correct result, it picks it out of the same ones and
the number doesn't seem to store correctly, the bottom codes works as it suppose to work.)
Code:
lastCol = Cells(215, Columns.Count).End(xlToLeft).Column
Dim C As New Collection, I As Integer, rdom As Integer
rowFOUR = 216
colFOUR = 2
'cntHIT = 0
rowtest = 216
For I = 2 To lastCol - 1
If Cells(rowFOUR, colFOUR) <> "" Then
Cells(rowtest, "W") = colFOUR
num = Cells(rowtest, "W")
C.Add CStr(num), CStr(num)
rowtest = rowtest + 1
End If
colFOUR = colFOUR + 1
Next I
n = 0
Row = 216
Do
I = Int(Rnd * C.Count + 1)
Cells(Row, "X") = I
C.Remove (I)
Row = Row + 1
n = n + 1
Loop While n <= 15 'numTimes >= 0
Code:
Dim C As New Collection, I As Integer
Row = 215
For I = 1 To 11
num = Cells(Row, "W")
C.Add CStr(num), CStr(num)
Row = Row + 1
Next I
I = Int(Rnd * C.Count + 1)
x = 216
Do
Cells(x, "x") = C.Item(I)
C.Remove (I)
I = Int(Rnd * C.Count + 1)
x = x + 1
Loop Until x >= 250