Jeffrey Mahoney
Well-known Member
- Joined
- May 31, 2015
- Messages
- 3,142
- Office Version
- 365
- Platform
- Windows
I have code that removes previous Conditional Formatting (CF) and then creates new ones. It works to remove one CF, but errors out after that. The problem with the code below is that for each CF I delete there is one less CF to evaluate. In other words, if I have three CFs and delete the first one, #2 shifts into #1 position and #3 shifts into #2 position. This prevents the code from evaluating all the CFs and errors out at the end because there are no longer that many CFs to evaluate.
How can I evaluate all the CFs and delete them all at once?
How can I evaluate all the CFs and delete them all at once?
VBA Code:
On Error Resume Next
For Each CF In Sel.FormatConditions
If CF.Type = xlExpression And InStr(CF.Formula1, "=AND(") > 0 And InStr(CF.Formula1, "<1000") > 0 Then
CF.Delete
End If
Next CF
On Error GoTo 0