Clearcontents, not conditional format.

user21136

Active Member
Joined
Sep 20, 2003
Messages
325
Hi,

Using Excel 2003.

I'd like to clear some cells using VBA...

Code:
            .Range("C5:C35").ClearContents
            .Range("D5:D35").ClearContents
            .Range("E5:E35").ClearContents
            .Range("H5:H35").ClearContents

These cells all have conditional formating from row 6 to 36.

In row 6, conditional format for example: Formula is =C5<>""

When I run the macro it clears the contents of C5:C35 & H5:H35 fine BUT where there are values in D5:D35 & E5:E35 it clears the conditional formating too.

Can't figure out why, any ideas please?

Regards, Glenn.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
try
Code:
[FONT=Verdana]Option Explicit
Sub try()
Dim c As Range
For Each c In Range("C5:C35,D5:D35,E5:E35,H5:H35")
 If c.Value <> "" Then c.ClearContents
Next
End Sub
[/FONT]
[FONT=Courier New][/FONT]
 
Upvote 0
Hi pedie,

Thank you but it's still doing exactly the same as above.

Weird! :confused:

I guess worst case I could copy/replace the Conditional Formatting from other cells outside the range.

Cheers, Glenn
 
Upvote 0
Apologies,

Tt seem this problem is cause by Worksheet_Change code. I've deleted it and Clearcontents is now does NOT delete the Conditional Format.

A bit off topic but it there a way to disable Worksheet_Change code within another macro?

Thanks.
Glenn.

Nevermind... I had: Application.EnableEvents = False - in the wrong spot. Wow!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,740
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top