Delete Method as it applies to format Condition object

D

DTP

I am trying delete conditional formats for a specific range of cells. The
Help documentation all say to use the Delete Method to delete a
formatcondition but I do not see a specific delete method for Format
conditions. Here are some instances I have tried but all generate errors.
With Worksheets(TargetWS).Range(Cells(5, 5), Cells(TargetRw, 5))
.DeleteFormatConditions (1)
.DeleteFormatConditions (2)
.DeleteFormatConditions (3)
End With
or
Worksheets(TargetWS).Range(Cells(5, 5), Cells(TargetRw, )).FormatConditions
(1).Delete

Does anyone know the syntax for using the Delete Method to delete
conditional formats (Format Conditions)?

Thanks
 
S

Sam Wilson

Worksheets("X").Range("A1").FormatConditions(1).Delete

is right - if you get run time error 1004 it's because there are no
conditional format conditions to delete! To avoid that you can use

On error resume next
Worksheets("X").Range("A1").FormatConditions(1).Delete


Sam
 
J

Jacob Skaria

Msgbox Range("d:d").FormatConditions.Count

Range("d:d").FormatConditions(1).Delete

If this post helps click Yes
 
D

DTP

Ok, So thanks for clearing up the question on the correct use of the Delete
Method on FormatConditions. This now works. However I needed to change the
way I addressed the range and the sequence of deletes. Here is the final
working module. There were 2 additional issues.
1. In my range was a mix of cells with and without Cond Formats. that was
genrating the 1004 code. The "On error resume next" got me past that.
2. Then becasue I was deleteing Format Condition (1) first by the time I got
to FormatCondition (3) there was no 3, it became FormatCondition (1) when the
other 2 were deleted. so it looked like it wasn't working.
Any way it works now and Thanks All for your help! Here is the final solution.

On Error Resume Next
For Each c In Worksheets(TargetWS).Range(Cells(5, 6), Cells(TargetRw, 6))
c.FormatConditions(2).Delete
c.FormatConditions(1).Delete
Next c
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top