Conditional Format

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Conditional Format

Post by jstevens »

I have a range that has conditional formatting. Let's call the range("M5:N100").

When I use VBA to delete a one or more rows within the range (not the entire row) the conditional format changes as to the "Applies To" section of the condition. In this example we can use: =$M$6:$N$100.

The delete routine uses:

Code: Select all

For i = 25 to  10  Step -1
	Range("M" & i & ":N" & i ).Delete Shift:=xlUp
Next i
Your suggestions are appreciated.
Regards,
John

User avatar
HansV
Administrator
Posts: 78555
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Conditional Format

Post by HansV »

What is your question? :scratch:
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Conditional Format

Post by jstevens »

How do I prevent the conditional format "Applies To" section from changing? Before the code is run the "Applies To" formula is: =$M$6:$N$100.

After the code is run it changes to something other the initial formula. One example: =$M$6:$N$40
Regards,
John

User avatar
HansV
Administrator
Posts: 78555
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Conditional Format

Post by HansV »

Deleting rows or columns will of course change the 'Applies to' range. So you have to reapply the desired range afterwards.
The FormatCondition object has a ModifyAppliesToRange method.
Best wishes,
Hans