Eloise T
Active Member
I receive a regular report for each of my customers but the number of rows will vary based on the amount of business that particular customer has. Each customer has their own tab (worksheet) in the workbook, except for tab #1 which is where I document formula information. For whatever reason (I believe due to frequently appending rows from the regular reports to the tabs), my current CFs seem to mysteriously change the range on their own and I have to go back into the Conditional Formatting to “reset” them back to what they need to be hence the desire and need to automate via a VBA macro.
Each report has the same column headings/titles which use Rows 1 and 2, so the Conditional Formats start in Row 3 (see below). I plan to put a button in the “Formula Info” tab (worksheet #1) that I can use to initiate the macro.
Each report has the same column headings/titles which use Rows 1 and 2, so the Conditional Formats start in Row 3 (see below). I plan to put a button in the “Formula Info” tab (worksheet #1) that I can use to initiate the macro.
Code:
Sub CFsReset()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Formula Info" And ws.Name <> "Sheet2" Then
If ws.Cells(Rows.Count, 3).End(xlUp).Row > 2 Then
With ws.[A3:M3].Resize(ws.Cells(Rows.Count, 3).End(xlUp).Row - 2)
' > > > This VBA changes/resets the Conditional Formats for cell rows ~3 to 5003 in the Columns C, K, L, and M.
' A3:M3 array tells where to apply change(s). (Rows.Count, 3) tells in which row to start.
.FormatConditions.Add Type:=xlExpression, Formula1:"=OR($C3="D70",$C3="E70",$C3="KDL70",$C3="LC70",$C3="LC-70",$C3="M70",$C3="PNC70",$C3="PNL70",$C3="PNR70")"
.FormatConditions(1).Interior.ColorIndex = 3 'Red =$C$3:$C$5003
.FormatConditions.Add Type:=xlExpression, Formula1:"=OR($C3="M75",$C3="P75",$C3="UN75")"
.FormatConditions(1).Interior.ColorIndex = 7 'Magenta =$C$3:$C$5003
.FormatConditions.Add Type:=xlExpression, Formula1:"=OR($C3="LC80",$C3="LC-80",$C3="M80",$C3="PNE80",$C3="PNL80")"
.FormatConditions(1).Interior.ColorIndex = 33 'Light Blue =$C$3:$C$5003
.FormatConditions.Add Type:=xlExpression, Formula1:=OR($C3="RS84")
.FormatConditions(1).Interior.ColorIndex = 15 'Brown =$C$3:$C$5003
.FormatConditions.Add Type:=xlExpression, Formula1:=OR($C3="DM85")
.FormatConditions(1).Interior.ColorIndex = 33 'Violet =$C$3:$C$5003
.FormatConditions.Add Type:=xlExpression, Formula1:=OR($C3="LC90")
.FormatConditions(1).Font.ColorIndex = 14 'Green
.FormatConditions(1).Interior.ColorIndex = 6 'Yellow =$C$3:$C$5003
.FormatConditions.Add Type:=xlExpression, Formula1:=OR($F3="REBILLED",$F3="REPAID",$F3="PAID")
.FormatConditions(1).Font.ColorIndex = 7 'Magenta
.FormatConditions(1).Interior.ColorIndex = 50 'Green =$F$3:$F$5003
.FormatConditions.Add Type:=x1Expression, Formula1:=$L3="LEN ≠ 9"
.FormatConditions(1).Interior.ColorIndex = 3 'Red Bold =$K$3:$K$5003,$M$3:$M$5003
End With
End If
End If
Next
End Sub
Last edited: