formula off text colour

ajp

Board Regular
Joined
Nov 17, 2002
Messages
54
Hi,

If I have a cell (b1) where the text colour is say red, I would like a formula that puts a "R" in (c1).

I also have text that is green, blue.

I have tried @if function using b1=Selection.Font.ColorIndex = 3, but this doesn't work any ideas
:pray:
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,279
Assuming the colors are not due to Conditional Formatting, which appears to be the case by your question, you will need a UDF to do what you want. Place the following code in a standard VBA module:

Function CellColor(rng As Range) As String
Select Case rng.Interior.ColorIndex
Case 3: CellColor = "Y"
Case 4: CellColor = "G"
Case 6: CellColor = "R"
Case 41: CellColor = "B"
Case Else: CellColor = ""
End Select
End Function


An example formula would be (assuming A1 contains color and you are entering the formula in cell B1):
=CellColor(A1)
 

ajp

Board Regular
Joined
Nov 17, 2002
Messages
54
can't seems to get it to work. I have pasted formula and in module 1 but it doesn't seem to do anything

:cry:
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,279
I transposed two values in there...Yellow is 6 and Red is 3. Please adjust.
 

Forum statistics

Threads
1,181,785
Messages
5,932,039
Members
436,816
Latest member
Composh

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