L
Legacy 502047
Guest
Hi everyone,
I'm new to collections and I keep getting a "subscript out of range" error on the underlined bit of code when I'm trying to set the value of the cell, wondering where I'm going wrong here?
Sub GetRandomEmptyCell()
Dim i, j, randomcell As Integer
Dim allcells As New Collection
For i = 1 to 10
For j = 1 to 4
If Cells(i, j) = "" Then
allcells.Add Cells(i, j)
End If
Next j
Next i
If allcells.Count >= 1 Then
randomcell = Rnd * allcells.Count
allcells(randomcell).Value = 2
allcells.Remove randomcell
End If
End Sub
Thanks for your help
yuro0804
I'm new to collections and I keep getting a "subscript out of range" error on the underlined bit of code when I'm trying to set the value of the cell, wondering where I'm going wrong here?
Sub GetRandomEmptyCell()
Dim i, j, randomcell As Integer
Dim allcells As New Collection
For i = 1 to 10
For j = 1 to 4
If Cells(i, j) = "" Then
allcells.Add Cells(i, j)
End If
Next j
Next i
If allcells.Count >= 1 Then
randomcell = Rnd * allcells.Count
allcells(randomcell).Value = 2
allcells.Remove randomcell
End If
End Sub
Thanks for your help
yuro0804