Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Conditional Formatting and Interior.ColorIndex

Windows XP Pro SP2
Excel 2002 SP3

Seems that cells that are conditionally formatted don't return an expected
Interior.ColorIndex value.

I am using this bit of code:

Set rng1 = Range("B20:P20")
For Each c1 In rng1.Cells
v1 = c1.Value
If v1 < "" Then
Set rng2 = Range(c1.Offset(3, 0), c1.Offset(32770, 0))
rng2.FormatConditions.Add xlCellValue, xlEqual, v1
rng2.FormatConditions(1).Interior.ColorIndex = 4
rng2.FormatConditions.Add xlCellValue, xlNotEqual, v1
rng2.FormatConditions(2).Interior.ColorIndex = 46
End If
Next c1

This works fine and colors the interiors as I would expect. However, if I
add this after the last line above

MsgBox Range("G23").Interior.ColorIndex 'G23 is colored red (46)

the message box says -4142.

What's up with that?

Any help greatly appreciated.

-gk-

GO TAR HEELS ! ! !



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Conditional Formatting and Interior.ColorIndex


-4142 is the value assigned to at least two Excel constants...
xlNone and xlColorIndexNone

Colors provided by Conditional formatting operate by their own rules.
They cannot be accessed using "colorindex".
See the Chip Pearson discussion here...
http://www.cpearson.com/excel/CFColors.htm
Get plenty of sleep first and pack a lunch. <g

You may have some interest in the free Excel add-in "Determine Colors".
It can be downloaded from the bottom of the Products page at my website.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





"Farrar Tweety"
wrote in message
Windows XP Pro SP2
Excel 2002 SP3

Seems that cells that are conditionally formatted don't return an expected
Interior.ColorIndex value.
I am using this bit of code:

Set rng1 = Range("B20:P20")
For Each c1 In rng1.Cells
v1 = c1.Value
If v1 < "" Then
Set rng2 = Range(c1.Offset(3, 0), c1.Offset(32770, 0))
rng2.FormatConditions.Add xlCellValue, xlEqual, v1
rng2.FormatConditions(1).Interior.ColorIndex = 4
rng2.FormatConditions.Add xlCellValue, xlNotEqual, v1
rng2.FormatConditions(2).Interior.ColorIndex = 46
End If
Next c1

This works fine and colors the interiors as I would expect. However, if I
add this after the last line above

MsgBox Range("G23").Interior.ColorIndex 'G23 is colored red (46)

the message box says -4142.

What's up with that?

Any help greatly appreciated.

-gk-

GO TAR HEELS ! ! !



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Conditional Formatting and Interior.ColorIndex


Thank you Jim, and sorry for the double post. Chip's site has long been
bookmarked, so I suppose I probably should have looked there first. <g

Looks like I'll be bookmarking your site as well. Thanks!!

-gk-


"Jim Cone" wrote in message
...

-4142 is the value assigned to at least two Excel constants...
xlNone and xlColorIndexNone

Colors provided by Conditional formatting operate by their own rules.
They cannot be accessed using "colorindex".
See the Chip Pearson discussion here...
http://www.cpearson.com/excel/CFColors.htm
Get plenty of sleep first and pack a lunch. <g

You may have some interest in the free Excel add-in "Determine Colors".
It can be downloaded from the bottom of the Products page at my website.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





"Farrar Tweety"
wrote in message
Windows XP Pro SP2
Excel 2002 SP3

Seems that cells that are conditionally formatted don't return an expected
Interior.ColorIndex value.
I am using this bit of code:

Set rng1 = Range("B20:P20")
For Each c1 In rng1.Cells
v1 = c1.Value
If v1 < "" Then
Set rng2 = Range(c1.Offset(3, 0), c1.Offset(32770, 0))
rng2.FormatConditions.Add xlCellValue, xlEqual, v1
rng2.FormatConditions(1).Interior.ColorIndex = 4
rng2.FormatConditions.Add xlCellValue, xlNotEqual, v1
rng2.FormatConditions(2).Interior.ColorIndex = 46
End If
Next c1

This works fine and colors the interiors as I would expect. However, if I
add this after the last line above

MsgBox Range("G23").Interior.ColorIndex 'G23 is colored red (46)

the message box says -4142.

What's up with that?

Any help greatly appreciated.

-gk-

GO TAR HEELS ! ! !





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Conditional Formatting and Interior.ColorIndex

If you use this syntax it will produce the ColorIndex number you are looking
for.

MsgBox Range("G23").FormatConditions(2).Interior.ColorInd ex

The problem is that you cannot use a generic FormatConditions, it must be
specific as (1), (2) or (3).



"Farrar Tweety" wrote:

Windows XP Pro SP2
Excel 2002 SP3

Seems that cells that are conditionally formatted don't return an expected
Interior.ColorIndex value.

I am using this bit of code:

Set rng1 = Range("B20:P20")
For Each c1 In rng1.Cells
v1 = c1.Value
If v1 < "" Then
Set rng2 = Range(c1.Offset(3, 0), c1.Offset(32770, 0))
rng2.FormatConditions.Add xlCellValue, xlEqual, v1
rng2.FormatConditions(1).Interior.ColorIndex = 4
rng2.FormatConditions.Add xlCellValue, xlNotEqual, v1
rng2.FormatConditions(2).Interior.ColorIndex = 46
End If
Next c1

This works fine and colors the interiors as I would expect. However, if I
add this after the last line above

MsgBox Range("G23").Interior.ColorIndex 'G23 is colored red (46)

the message box says -4142.

What's up with that?

Any help greatly appreciated.

-gk-

GO TAR HEELS ! ! !




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
problem with interior.colorindex Peter Rooney Excel Programming 7 January 20th 06 12:31 PM
Use of Interior.ColorIndex liquidhot Excel Programming 4 June 27th 05 07:22 PM
interior.colorindex used with conditional formatting Wazooli Excel Worksheet Functions 7 February 25th 05 01:01 AM
conditional formatting and interior.colorindex Wazooli Excel Programming 1 February 24th 05 05:53 PM
Testing for Interior.ColorIndex JeffBo Excel Programming 7 May 17th 04 09:41 PM


All times are GMT +1. The time now is 09:08 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"