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:
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,224
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,224
I transposed two values in there...Yellow is 6 and Red is 3. Please adjust.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,992
Members
414,115
Latest member
SFUser

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