Use the rnd
function to determine the row and column.
The formula is Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
So assuming you can see roughly 25 rows and 25 columns it would be:
Dim r As Long
Dim c As Long
r = Int((25 * Rnd) + 1)
c = Int((25 * Rnd) + 1)
Debug.Print "row: " & r, "column: " & c
Cells(r, c).Interior.Color = vbRed
Returning a cell:
Function randomizecell() As Range
Dim r As Long
Dim c As Long
r = Int((25 * Rnd) + 1)
c = Int((25 * Rnd) + 1)
Set randomizecell = Cells(r, c)
End Function
Sub colorcell()
Dim cell As Range
Set cell = randomizecell()
cell.Interior.Color = vbRed
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…