polarisking
Member
This macro deletes all existing CFs, then sets 2 new ones:
Thanks in advance for any assitance/explanation.
- The first, based on a MOD 2 test vs. Row #, sets zebra stripes (light blue)
- The second, based on the cell >3 in columns 1 and 4, colors the cell/Font.
Thanks in advance for any assitance/explanation.
Code:
Sub CondFormat()
Dim ws As Worksheet
Dim cell As Range
Dim ctr As Long
Dim StartTimer As Double
Dim LastCol As Long
Dim LastRow As Long
Dim FirstRow As Long
Dim Rng_All As Range
Dim Rng_PortPct As Range
Dim Rng_ReconPortPct As Range
Dim RR As Range
'================================================================================
StartTimer = Timer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
'================================================================================
LastCol = Cells(5, Columns.Count).End(xlToLeft).Column
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
FirstRow = 1
Set Rng_All = Range(Cells(FirstRow, 1), Cells(LastRow, LastCol))
Set Rng_PortPct = Range(Cells(FirstRow, 1), Cells(LastRow, 1))
Set Rng_ReconPortPct = Range(Cells(FirstRow, 4), Cells(LastRow, 4))
Set RR = Union(Rng_PortPct, Rng_ReconPortPct)
'================================================================================
Rng_All.FormatConditions.Delete
'
Rng_All.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=0"
'Rng_All.FormatConditions(Rng_All.FormatConditions.Count).SetFirstPriority
'Rng_All.FormatConditions(1).SetFirstPriority
With Rng_All.FormatConditions(1)
.Font.Color = vbBlack
.Interior.Color = RGB(218, 238, 243)
End With
Rng_All.FormatConditions(1).StopIfTrue = False
RR.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=A1>3"
With RR.FormatConditions(2)
.Interior.Color = vbRed
.Font.Bold = True
.Font.Color = vbWhite
End With
'================================================================================
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Complete in " & Format(Timer - StartTimer, "#0.000") & " seconds"
End Sub
