Answer_the_question
New Member
- Joined
- Nov 19, 2015
- Messages
- 17
I am trying to create a macro to alternate row colours in a selected range. Currently using conditional formatting and this is what the code looks like right now
I use the subtotal function so that the conditional formatting will still work when I group rows, but I dont think this will work if i have a column in the counta range that has a blank cell.
Anyways the really issue is that I can't get the subtotal function to use the top left cell of my selection in the formula (currently have to manually change it to the correct cell after running the macro)
The conditional formatting also appears to only work on the number of rows I used during the initial recording (ie if when I recorded the macro there were 8 rows in the test table, when i apply the macro to a new table it only works on the first 8 rows even if there are 20 rows)
Any help would be greatly appreciated!
Thank you
Less experienced with VBA so the mroe straightforward the better
Code:
Sub Row_Shadding()
'
' Row_Shadding Macro
'
'
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(SUBTOTAL(103,$E$5:$E5),2)=0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -4.99893185216834E-02
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
I use the subtotal function so that the conditional formatting will still work when I group rows, but I dont think this will work if i have a column in the counta range that has a blank cell.
Anyways the really issue is that I can't get the subtotal function to use the top left cell of my selection in the formula (currently have to manually change it to the correct cell after running the macro)
The conditional formatting also appears to only work on the number of rows I used during the initial recording (ie if when I recorded the macro there were 8 rows in the test table, when i apply the macro to a new table it only works on the first 8 rows even if there are 20 rows)
Any help would be greatly appreciated!
Thank you
Less experienced with VBA so the mroe straightforward the better

Last edited by a moderator: