Random Color the selected range
Sub BGColors()
Dim r As Byte, g As Byte, b As Byte
Dim iRow As Integer, iCol As Integer
Dim iRows As Integer, iCols As Integer
Dim rng As Range, rngFill As Range
Dim strMsg As String
Dim iIcon As Integer, strTitle As String
On Error GoTo ErrorHandler
iRows = 9
iCols = 9
Set rng = ActiveCell
For iCol = 0 To iCols
For iRow = 0 To iRows
r = WorksheetFunction.RandBetween(0, 255)
g = WorksheetFunction.RandBetween(0, 255)
b = WorksheetFunction.RandBetween(0, 255)
Set rngFill = rng.Offset(iRow, iCol)
With rngFill.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = RGB(r, g, b)
End With
Next iRow
Next iCol
ProcedureDone:
Exit Sub
ErrorHandler:
strTitle = "BGColors Macro Error"
iIcon = vbOKOnly + vbExclamation
strMsg = Err.Number & " " & Err.Description
MsgBox strMsg, iIcon, strTitle
Resume ProcedureDone
End Sub