Quickly Clear Conditional Formatting

Here is a simple sub that deletes conditional formatting from a selection. The code does some prelim checking to see that it is actually acting on a range, and it mimics Excel's usual behavior (like a good VBA procedure should, if I may say so) by acting on the entire worksheet if you only select a single cell. However I recommend just selecting the range before you run the code.

Sub Clear_Cond_Formatting()
Dim rng As Excel.Range

If TypeName(Selection) <> "Range" Then Exit Sub

Select Case Selection.Cells.count
    Case 1
       Set rng = Cells
    Case Else
       Set rng = Selection
End Select

On Error Resume Next
rng.FormatConditions.Delete
On Error GoTo 0
End Sub

Enjoy,
JP

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 3 Comments:

  1. Jon Peltier writes:

    Aren't the second and third "If Typename" lines redundant? If it's not a range, then it's already left the sub.

  2. JP writes:

    Thanks Jon. That's what I get for cutting and pasting without reading!

    –JP

  3. JP writes:

    Here is the revised code…

    Sub Clear_Cond_Formatting()
    Dim rng As Excel.Range

    If TypeName(Selection) <> "Range" Then Exit Sub

    Select Case Selection.Cells.count
    Case 1
    Set rng = Cells
    Case Else
    Set rng = Selection
    End Select

    On Error Resume Next
    rng.FormatConditions.Delete
    On Error GoTo 0

    End Sub

Comments on this article are closed. Why?

Site last updated: February 12, 2012