View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RyanH RyanH is offline
external usenet poster
 
Posts: 586
Default 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