ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditional Formatting in a For Each Worksheet Loop (https://www.excelbanter.com/excel-programming/404399-conditional-formatting-each-worksheet-loop.html)

RyanH

Conditional Formatting in a For Each Worksheet Loop
 
I currently have 1 conditional format on all worksheets. I want to add a 2nd
conditional format to all worksheets. This loop does not seem to work. Does
anyone have any ideas why?

Sub CFormat ()

Dim wks As Worksheet

For Each wks in Worksheets
'adds a bottom line to every 5th rows
wks.UsedRange.FormatConditions.Add Type:=xlExpression,
Formula2:="=MOD(ROW(),5)=0"
With wks.UsedRange.FormatConditions(2).Borders(xlBottom )
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

Next wks

End Sub


All times are GMT +1. The time now is 07:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com