Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional Format issue

I have an Excel Add-In for Office 2007. In the application, I have a need to
color the entire row or column based on application created named ranges. I
tried to use Range.Interior.Color to highlight rows or columns for which the
user created named ranges from the application. However, the issue is I have
no way to restore the color the user previously had.

So, I decided to use conditional formating. I union all ranges for which
named ranges are created by the user using the add-in. Then I create
conditional formating for that range with a simple expression "=TRUE" and
then set the interior color in the conditional format. Works great - does not
impact the cell format user has.

Excel.FormatCondition formatCondition = mappedRange.FormatConditions.Add(
XlFormatConditionType.xlExpression,
XlFormatConditionOperator.xlEqual,
"=TRUE",
missing,
missing,
missing,
missing,
missing) as FormatCondition;
if (formatCondition != null) {
formatCondition.StopIfTrue = false;
formatCondition.Priority = 1;
formatCondition.Interior.ColorIndex = 37;
}

I have a highlight toggle button in the Add-In ribbon, which basically
creates or delete the conditional format. In the Add-in a member variable
persists the FormatCondition object that was created. The conditional format
object will be deleted when user turn off highlight toggle button. Works fine
in most cases, but found an issue.

The issue is when user had created conditional format outside of the add-in.
The user creates a named range using the application add-in. Set the
highlight on from the ribbon. Later, user creates their own conditional
format (2D color scale) such that it intersect the range used by the
highlight. Now, when user try to remove the highlight, the
formatCondition.Delete() raises an exception. When I looked into it, the
member variable that had the reference to the formatCondition that created is
no more a single item instead it represents a collection. So, I tried to do
something like formatCondition.AppliesTo.FormatConditions to loop around all
the condition and delete the one I created using the expression test "=TRUE".
While I am looping thru, I first hit up on the one user created which is
color scale condition, so I tried to access the formatCondition.Type == 2 and
right there it raises expection. The reason I found was that the
formatCondition.Type is not accessible for the user created one.

My question to you is how can I delete the format condition that I
programmtically created without impacting the user created format conditions.

Your help on this will be much appreciated.
--
Sriram.K
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional format issue Mike Busch[_2_] Excel Discussion (Misc queries) 3 November 29th 08 05:38 PM
Conditional format issue Patrick C. Simonds Excel Worksheet Functions 8 January 17th 08 05:37 PM
Conditional Format issue Patrick C. Simonds Excel Discussion (Misc queries) 5 August 1st 07 09:26 PM
Conditional Format Issue Dean F Excel Worksheet Functions 8 June 8th 06 09:48 AM
Conditional Format Issue Darkdrew Excel Worksheet Functions 3 April 13th 06 04:40 PM


All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"