Selecting 2+ random cells

  • Thread starter Thread starter Phillip
  • Start date Start date
P

Phillip

How can I select 2 or more random cells in a spreadsheet?
Not adjacent cells but cells that are at different areas
of the spreadsheet such as B6, C11, and E16.
 
One way:

Sub SelectRandomCell(Adding As Boolean)
Dim x As Integer
Dim y As Integer

Do
x = Int(16384 * Rnd(1) + 1)
y = Int(256 * Rnd(1) + 1)
Loop While Adding And (Not Intersect(selection, Cells(x, y)) Is Nothing)
If Adding Then
Union(selection, Cells(x, y)).Select
Else
Cells(x, y).Select
End If
End Sub

Sub test()
SelectRandomCell False
SelectRandomCell True
SelectRandomCell True
End Sub

-Dave
 
If you simply want to select the cells to add specialized
formatting, select the first cell and then hold down CTRL
while selecting the other cells. If you want Excel to
randomize cell selection, try the other guy's suggesion.
 
Back
Top