The code will only really work when the gamezone is completely empty. At the point the range is C4:I10.
once you populate the gamezone the range returned by specialcell blank is a non contiguous one. The although the random number is within the count of cells of that non contiguous range
the .Cells(x) reference is only based on the first area of the non contiguous range. So for some random values this will be in that first area, for others in will be beyond
the first area but within the gamezone area, so it appears okay. for other values it will be outside the gamezone completely.
here is an example. range C4:I10 is empty except for E4.
The range address is $C$4:$D$4,$F$4:$I$4,$C$5:$I$10
If your random number is 3 then the actual cells returned is $C$5 and not $F$4
Here is some code that stores empty cells and then random selects one of them. Once selected it is removed from the collection.
Sub Test()
Dim gameZoneSlots As Collection
Dim slot As Range
Dim randomSlot As Long
Set GSWS = Sheets("Game Sheet")
Set Anchor = GSWS.Range("B3")
Set gamezone = Anchor.Offset(1, 1).Resize(7, 7)
Set gameZoneSlots = New Collection
For Each slot In gamezone.Cells
If slot = "" Then
gameZoneSlots.Add slot, CStr(gameZoneSlots.Count + 1)
End If
Next
'Put in Specials
For n = 0 To 10
If gameZoneSlots.Count > 0 Then
randomSlot = Int(Rnd * gameZoneSlots.Count) + 1
Set cel = gameZoneSlots(randomSlot)
GSWS.Range("L3").Offset(n).Copy cel
gameZoneSlots.Remove randomSlot
Else
MsgBox "Grid is full"
Exit For
End If
Nextn: Next n
End Sub
Bookmarks