I have a range of cells which have conditional formatting applied.
The aim was to visually separate the values with a positive, negative, and no change.
How can I use VBA to check if the cells have conditional formatting applied to them (such as color of the cell due to being a negative number)?
See if the Count is zero or not:
Sub dural()
MsgBox ActiveCell.FormatConditions.Count
End Sub
To use VBA to check if a cell has conditional formatting use the following code
Dim check As Range
Dim condition As FormatCondition
Set check = ThisWorkbook.ActiveSheet.Cells.Range("A1") 'this is the cell I want to check
Set condition = check.FormatConditions(1) 'this will grab the first conditional format
condition. 'an autolist of methods and properties will pop up and
'you can see all the things you can check here
'insert the rest of your checking code here
You can use parts of this code above with a for each loop to check all the conditions within a particular range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With