Answers for "set data sheet alternate row color access vba"

VBA
1

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
Posted by: Guest on February-18-2021

Code answers related to "VBA"

Browse Popular Code Answers by Language