J
jbb16x99
I'm relatively new to excel macros so bare with me. I've written a
simple formatting macro that I want to enhance. The macro is as
below.
Sub CondFormat()
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
Selection.FormatConditions(2).Font.ColorIndex = 2
Selection.FormatConditions(2).Interior.ColorIndex = 3
Range("A1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range(myrange).Select
End Sub
The macro fails and gives me an error message if I run it on cells
already containing the conditional formatting. I'm not sure why. So,
I'd like to make the macro check first to see if this conditional
formatting already exists. If it does, then I want the macro to
delete the conditional formatting. If it doesn't already exist, then
execute the conditional formatting. Additionally, no matter if this
conditional formatting already exists or not, I'd like to always color
cell A1 with ColorIndex 6.
Can someone help? Thanks in advance.
simple formatting macro that I want to enhance. The macro is as
below.
Sub CondFormat()
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, _
Formula1:="=+$A$1"
Selection.FormatConditions(1).Font.ColorIndex = 2
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, _
Formula1:="=-$A$1"
Selection.FormatConditions(2).Font.ColorIndex = 2
Selection.FormatConditions(2).Interior.ColorIndex = 3
Range("A1").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Range(myrange).Select
End Sub
The macro fails and gives me an error message if I run it on cells
already containing the conditional formatting. I'm not sure why. So,
I'd like to make the macro check first to see if this conditional
formatting already exists. If it does, then I want the macro to
delete the conditional formatting. If it doesn't already exist, then
execute the conditional formatting. Additionally, no matter if this
conditional formatting already exists or not, I'd like to always color
cell A1 with ColorIndex 6.
Can someone help? Thanks in advance.