Weird UDF problem

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
2,114
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
Hello guys
I wasn't expecting to post a question here, but here it is:
related to another post here (https://www.mrexcel.com/forum/excel...ng-cell-value-based-another-cells-colour.html) I decided to make a small UDF to determine the color of a cell.
At first it all went well:
Code:
Function CellColor1(rng1 As Range)
    CellColor1 = rng1.Interior.Color
End Function
No problem here - I enter the formula in a cell =CellColor1(E15), select the cell to inspect and I get the result as expexted.
However - next thing I decided was to get the actual color set by conditional format. So I change to this:
Code:
Function CellColor1(rng1 As Range)
    CellColor1 = rng1.DisplayFormat.Interior.Color
End Function
I refresh the formulas in the sheet and I end up with #VALUE ! error instead.
So I check it in the Immediate window:
Code:
?CellColor1(activecell)
And there I got the expected result: 16777215
But the cells with the function still show a #VALUE ! error ???!!!
Any ideas?

BTW - currently working on Win10 + Office 365 ProPlus
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I suspect that .DisplayFormat (like .Find or .SpecialCells) will error when in a UDF used on a worksheet, but work fine when the UDF is called by a VB routine.
 
Upvote 0
Last edited:
Upvote 0
Not really. One problem with color based formulas, is that changing a cell's color (either manually or by CF) does not force calculation.
 
Upvote 0
The original source of the solution in stackoverflow should be here: http://www.vbaexpress.com/kb/getarticle.php?kb_id=190

Working at first glance.
However given the increase of complexity of conditional formatting I think it will not be 100% bulletproof - testing and evaluation pending :)
 
Last edited:
Upvote 0
Not really. One problem with color based formulas, is that changing a cell's color (either manually or by CF) does not force calculation.

Good point Mik, thanks for the tip.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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