creating text based on the color of the another cell in excel

marya

New member
Joined
Mar 13, 2015
Messages
3
Reaction score
0
Points
0
Hi

could anyone direct me, how I could assign a value to a cell based on the color of another cell? let say I would like cell B2 have value of 1 if Cell A2 is filled with blue color; otherwise, B2 to be assigned 0.

Regards
Maryam
 
Last edited:
Hi Maryam,

The only way I can see to do this is to use a macro to read the colour of the cell and react to it. Ideally it would be nice to use a conditional format, but they can't read colours.

It would be nice to have a sample workbook to look at with the potential colours you'll use and logic. Also, we'd want to know what version of Excel you have. (There isn't just one blue after Excel 2003, there's tints/shades/hues...)

FYI, I'm teaching a course all day, so I can't look at this till later, but if you can wait till the weekend, then I can look at it.
 
Creating text based on the color of adjacent cell

Thanks a lot for the reply. Attached is the sample file. My office version is 2010.would you please direct me about macro. I am eagerly looking forward to hearing from you.

Regards
Maryam
 

Attachments

  • Test.xlsx
    12.3 KB · Views: 15
Okay, so I knocked up a user defined function called ISBLUE() for this. You'll be able to use it as an Excel formula like this:

=ISBLUE(C4)

In order to do this, though, there are a couple of things you'll need to do:
  • First, the cells where you want to use this function must be formatted as something other than text. In the workbook you sent me, I had to set C4:C108 to the "General" format (although any number style should work)
  • Second, you need to add the macro to your project:
    • Open the workbook
    • Press Alt+F11 to open the Visual Basic Editor (VBE)
    • Press CTRL+R to show the Project Explorer
    • Drill down into the VBAProject for your workbook
    • Right click any item in that project and choose Insert --> Module
    • Within that module, paste the following code:
Code:
[INDENT=2]Public Function ISBLUE(rng As Range) As Long[/INDENT]
[INDENT=2]   If rng.Cells(1, 1).Interior.ColorIndex = 33 Then[/INDENT]
[INDENT=2]        ISBLUE = 1[/INDENT]
[INDENT=2]    Else[/INDENT]
[INDENT=2]        ISBLUE = 0[/INDENT]
[INDENT=2]    End If[/INDENT]
[INDENT=2]End Function[/INDENT]

  • Close the Visual Basic Editor

Now that you have the code in your workbook, you'll need to save it. But make sure you save it as a "Macro Enabled Workbook (*.xlsm)" type file, or you'll loose the macro

Once you've done all that, you should be able to use it as a formula in your workbook:

=ISBLUE(C4)

Sample file attached.
 

Attachments

  • ISBLUE.xlsm
    19.2 KB · Views: 12
Dear Ken,

Thanks a lot for your time and help.

Regards
Maryam
 
Back
Top