Conditional Formatting - How to get the cell colorindex

hstaubyn

Board Regular
Joined
Sep 13, 2010
Messages
93
I have a range of numbers which is subject to conditional formatting. The conditional formatting applied is a three-color-scale going from 0 to the highest value (red to yellow to green).

I have a for loop that looks at each cell in the range in turn and then sets the interior colour of some corresponding shapes depending on the colour of the cell, meaning that I need to get the colorindex rather than just reapplying the same conditional formatting somewhere else. This is fine when the cells are just filled normally, you can use the range("X100").interior.colorindex property and apply it to the relevant shape. This does not work, however, with conditional formatting. I have searched this and other sites, but the solutions I have found do not work. This is the code I have at the moment simplified with the troublesome line included:

When I run it I get a run-time error '438', Object doesn't support this property or method. I'm using Excel 2007.

Code:
Sub SetAllTechBubbleColour()


Dim iRange As Range


For Each iRange In Sheets("Sheet 2").Range("TechRankBubbleColour")
    iRange.Interior.ColorIndex = ActiveSheet.Range("H189").FormatConditions(1).Interior.ColorIndex
    MsgBox "Ok?"
Next iRange


End Sub

Strangely, these snippets of code do work:

Code:
Msgbox(Range("H189").FormatConditions.Count)

and

Msgbox(Range("H189").FormatConditions(1).Type)

I have also tried these approaches without success (same error at same point in code, i.e. when accessing the range's format conditions).

Get Displayed Cell Color (whether from Conditional Formatting or not)

http://www.xldynamic.com/source/xld.CFConditions.html

Conditional Formatting Colors

In these approaches the same error occurs at this point (or similar):

Code:
Public Function CFColorindex(rng As Range, _
                      Optional text As Boolean = False)
'---------------------------------------------------------------------
Dim oFC As FormatCondition
Dim sF1 As String
Dim iRow As Long
Dim iColumn As Long


   Set rng = rng(1, 1)
   If rng.FormatConditions.Count > 0 Then
      [B]For Each oFC In rng.FormatConditions[/B]

If anyone could tell me where I'm going wrong I would be extremely grateful.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Thanks for that suggestion, I have already tried it though and had the same problem with that code.

I have come across an excellent little work around though:

1. Copy the cells with the conditional formatting and paste into MS Word
2. Copy the newly pasted in table from MS Word
3. Select a cell in the excel spreadsheet and paste

The newly pasted table contains the same data and colours, but no conditional formatting!

Thank you Ashish for the suggestion - https://groups.google.com/forum/?fromgroups#!topic/microsoft.public.excel.misc/3kbkrAHUjIs%5B1-25%5D
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,684
Members
449,463
Latest member
Jojomen56

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