Can use VBA to find .Interior.Color of a cell, but can't if Conditional Formatting sets the color

jfarc

Active Member
Joined
Mar 30, 2007
Messages
314
I see that I can test for and find the Color Index of a cell by using the following VBA code:

VBA Code:
colorCode = Range("S4").Interior.Color

But, the above code will not return the visible Color Index code of a cell that has Conditional Formatting where the rules of the Conditional Formatting has changed the Color to something else.

So, if the cell in question has been set to have the Color Green (Index=65280), but a Conditional Format rule has changed the cell color to Red(Index=255), then the above code returns the originally hard set color of Green-65280, but not Red-255, which is what the user sees when looking at the cell.

How can I find through VBA what the CondForm'd Color has been set to?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,631
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
You can use the DisplayFormat property but only in a macro or event code... it will not work in a UDF (user defined function)...

colorCode = Range("S4").DisplayFormat.Interior.Color
 
Solution
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,700
Messages
5,766,010
Members
425,322
Latest member
galaxy6623top

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
Top