Formatting a cell with Text based off the color of another cell

aadam0906

New Member
Joined
Aug 6, 2024
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
I want to have cell A auto populate either 'PB' or 'AF' based off the color of cell B. Can anyone think of a way to do this, I did try conditional formatting but I could not figure out to make it work.

1722980060077.png
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Question: What is dictating the color of the row? Is it conditional formatting, or is this being done via a manual change?

The reason I ask, is that if this is being done via conditional formatting, you can use an IF function using the same logic populating the conditional formatting, to then populate AF/PB.

Now, on the other hand, if these rows are being colored by a manual process, then you will need to use VBA. I can put together some VBA For you, but I'll need to know the Color code that you are using for Yellow/Blue. To do this, click a yellow cell and run this VBA:
VBA Code:
Sub ColorCode()

MsgBox ActiveCell.Interior.Color

End Sub

Then do the same when selecting a Blue cell. And provide me those numbers.
 
Upvote 0
Also, to expand on my previous comment. Once you have those color codes, I'd create a function using VBA:
VBA Code:
Function COLORVALUE(x As Range)

COLORVALUE = "ColorNotFound"
If x.Interior.Color = "9985057" Then COLORVALUE = "PB" 'Blue Color Value
If x.Interior.Color = "65535" Then COLORVALUE = "AF" 'Yellow Color Value

End Function

Where you replace those color numbers (9985057,65535) with the color values provided by my previous code. This will create a new function in Excel:
Excel Formula:
=ColorValue(F4)

Where it will return "PB" if the interior color of that cell is Blue, and "AF" if it is yellow.

I hope this helps!

1722981422885.png
 
Upvote 0
Question: What is dictating the color of the row? Is it conditional formatting, or is this being done via a manual change?

The reason I ask, is that if this is being done via conditional formatting, you can use an IF function using the same logic populating the conditional formatting, to then populate AF/PB.

Now, on the other hand, if these rows are being colored by a manual process, then you will need to use VBA. I can put together some VBA For you, but I'll need to know the Color code that you are using for Yellow/Blue. To do this, click a yellow cell and run this VBA:
VBA Code:
Sub ColorCode()

MsgBox ActiveCell.Interior.Color

End Sub

Then do the same when selecting a Blue cell. And provide me those numbers.
Also, to expand on my previous comment. Once you have those color codes, I'd create a function using VBA:
VBA Code:
Function COLORVALUE(x As Range)

COLORVALUE = "ColorNotFound"
If x.Interior.Color = "9985057" Then COLORVALUE = "PB" 'Blue Color Value
If x.Interior.Color = "65535" Then COLORVALUE = "AF" 'Yellow Color Value

End Function

Where you replace those color numbers (9985057,65535) with the color values provided by my previous code. This will create a new function in Excel:
Excel Formula:
=ColorValue(F4)

Where it will return "PB" if the interior color of that cell is Blue, and "AF" if it is yellow.

I hope this helps!

View attachment 115063
Thank you, just when I think I am pretty Excel savvy. I have never used VBA so I will have to get myself up to speed with that.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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