Macro won't recognize conditional formatting

Matt40Forte

New Member
Joined
Jul 27, 2017
Messages
3
Hey Everyone,

I have a macro written in order to judge a cell based off its color. The code is below:

Function CheckColor1(range)
If range.Interior.Color = RGB(255, 0, 0) Then
CheckColor1 = "Stop"
ElseIf range.Interior.Color = RGB(0, 255, 0) Then
CheckColor1 = "Go"
Else
CheckColor1 = "Neither"
End If
End Function

This works for cells that I have filled manually, but if I have conditional formatting with the specified colors I just get "Neither".

Is there a way to modify this for it to work with conditional formatting fills?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
If you are using Excel 2010 or a later version, try:
Code:
range.DisplayFormat.Interior.Color

which allows determination of the format properties of range regardless of how they were established (i.e. manually or by CF).
 
Upvote 0
If you are using Excel 2010 or a later version, try:
Code:
range.DisplayFormat.Interior.Color

which allows determination of the format properties of range regardless of how they were established (i.e. manually or by CF).

Hi JoeMo, I am afraid DisplayFormat doesn't work with UDF's

Note that the DisplayFormat property does not work in user defined functions. For example, in a worksheet function that returns the interior color of a cell, you use a line similar to: Range(n).DisplayFormat.Interior.ColorIndex. When the worksheet function executes, it returns a #VALUE ! error
.


Range.DisplayFormat Property (Excel)
 
Upvote 0

Forum statistics

Threads
1,216,291
Messages
6,129,911
Members
449,540
Latest member
real_will_smith

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