Results 1 to 5 of 5

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

  1. #1

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



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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 by marya; 2015-03-13 at 07:11 AM.

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,306
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    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.
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3

    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
    Attached Files Attached Files

  4. #4
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,306
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    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:
    Public Function ISBLUE(rng As Range) As Long
    If rng.Cells(1, 1).Interior.ColorIndex = 33 Then
    ISBLUE = 1
    Else
    ISBLUE = 0
    End If
    End Function
    • 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.
    Attached Files Attached Files
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  5. #5
    Dear Ken,

    Thanks a lot for your time and help.

    Regards
    Maryam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •