Hi
I've only just joined the forum and I'm new to VBA. Please could somebody advise what is wrong with my code below which I want to automatically colour any cell in my worksheet according to the rule above.
I realise this can be achieved using conditional formatting but would be useful to know how to do as I am a beginner in VBA.
Thanks in advance.
I've only just joined the forum and I'm new to VBA. Please could somebody advise what is wrong with my code below which I want to automatically colour any cell in my worksheet according to the rule above.
Code:
Sub CondFormatZero()
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65280
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'
MyCell = ActiveCell.Address
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(MyCell>0,1,0)"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub
I realise this can be achieved using conditional formatting but would be useful to know how to do as I am a beginner in VBA.
Thanks in advance.