Conditional Formatting VBA

GordonLS

Board Regular
Joined
May 28, 2021
Messages
89
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good morning, so I am trying to clean up the code for this. This code will fill rows with color based off alternating order numbers from Row 2 thru Row 500.


Rows("2:500").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(SUMPRODUCT(--($e$2:$e2<>$e$1:$e1)),2)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.14996795556505
End With



What I would like to do is incorporate the following so that the rows selected are only the rows that have data in Column A.
'Range("A1").Select
'Selection.End(xlDown).Select
'lastRow = ActiveCell.Row

But I need the alternating fill to work from row A1 through the "lastRow" and for as many columns that have data.

Just let me know if more information is needed.

Gordon
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Like this?
VBA Code:
    Dim lr As Long
    lr = Cells(Rows.Count, "A").End(xlUp).Row

    Rows("2:" & lr).Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=MOD(SUMPRODUCT(--($e$2:$e2<>$e$1:$e1)),2)"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.14996795556505
    End With
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top