Can I Query Font Color of Cell

BobW

New Member
Joined
Mar 21, 2020
Messages
8
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hello,

Trying to query the font color of a cell. If my font color is red, I want to return the number 12. If font color is black (or auto), I want to return the number 4. Is this possible? Example below shows the result of querying the font color in Column A (result would be returned in column B)

ABCDEF
1
This is a red font text cell12
2
This is a black font text cell4
3
This is another red font text cell12

I run O365 Excel/Windows
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
It is possible only with VBA. What are the color numbers for your version of red?
 
Upvote 0
It is possible only with VBA. What are the color numbers for your version of red?
Hi 6StringJazzer. Thanks much! I think I could alter the if to "not black" -- i just picked the red font from the font palette. Does that help?
 
Upvote 0
Put this code into a standard module (like Module1) and use it in a sheet like this:
VBA Code:
Public Function FontNotBlack(R As Range) As Boolean

   FontNotBlack = R.Font.Color <> RGB(0, 0, 0)

End Function

$scratch.xlsm
AB
1testFALSE
2testFALSE
3testTRUE
4testFALSE
5testFALSE
6testTRUE
7testFALSE
8testFALSE
9testFALSE
Sheet17
Cell Formulas
RangeFormula
B1:B9B1=FontNotBlack(A1)
 
Upvote 0
Solution
Another option
+Fluff 1.xlsm
AB
1
2This is a red font text cell12
3This is a black font text cell4
4This is another red font text cell12
5This is automatic font colour4
Data
Cell Formulas
RangeFormula
B2:B5B2=IF(FontColour=0,1,FontColour)*4


Where FontColour is a defined name using
Excel Formula:
=GET.CELL(24,INDIRECT("rc[-1]",FALSE))

This will work for any font colour, but can be limited to just red & black.
 
Upvote 0
I did not know that was available. I normally don't think about Excel 4.0 macros. It might have to be explicitly enabled in the Trust Center in the current version of Excel.
 
Upvote 0
It might have to be explicitly enabled in the Trust Center in the current version of Excel.
Doesn't seem to need it. I don't have that checked, but it still works, which does seem a bit odd. :unsure:
 
Upvote 0
Put this code into a standard module (like Module1) and use it in a sheet like this:
VBA Code:
Public Function FontNotBlack(R As Range) As Boolean

   FontNotBlack = R.Font.Color <> RGB(0, 0, 0)

End Function

$scratch.xlsm
AB
1testFALSE
2testFALSE
3testTRUE
4testFALSE
5testFALSE
6testTRUE
7testFALSE
8testFALSE
9testFALSE
Sheet17
Cell Formulas
RangeFormula
B1:B9B1=FontNotBlack(A1)
Hi Jeff,

Thanks so much. This works!
 
Upvote 0
Hi Fluff,

Thanks so much! This solution works too!
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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