excel vba alternate row color
Sub OddEvenTab(ByRef pRange As Range, firstColor As Long, secondColor As Long)
With pRange
.Interior.ColorIndex = xlNone
' In Formula1: choose comma or semicolon (to avoid Error 5)
.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(1).Interior.Color = firstColor
.FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)<>0"
.FormatConditions(2).Interior.Color = secondColor
End With
End Sub
' ------------------------------------------------------------------------------
Sub TestMe()
OddEvenTab Range("A1:D12"), RGB(230, 230, 230), vbWhite
End Sub