I have recorded a macro that will add conditional formatting to 2 columns based on the values in 2 other columns. How do I
go about adding a loop, that would be based on Column "A" containing a value. (IF column “A” contains a value, put
conditional format into Columns “B” and “C” cells of that row). Another question I have regarding the recorded macro is, can
the selection.Borders be combined? or does each one have to have its own "With" and "End With"?
Thank you in advance
Sheet1
[HTML removed]
go about adding a loop, that would be based on Column "A" containing a value. (IF column “A” contains a value, put
conditional format into Columns “B” and “C” cells of that row). Another question I have regarding the recorded macro is, can
the selection.Borders be combined? or does each one have to have its own "With" and "End With"?
Thank you in advance
Code:
Sub Cond_Format()
'
' Cond_Format Macro
'
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=AND(D2>E2)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Color = -16751104
End With
With Selection.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Interior
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.599963377788629
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("C2").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=""AND(E2>D2)"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Color = -10477568
End With
With Selection.FormatConditions(1).Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlRight)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 10092543
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
Sheet1
[HTML removed]
Last edited by a moderator: