+ Reply to Thread
Results 1 to 9 of 9

Thread: Code: return the color index of a colored cell

  1. #1
    Registered User
    Join Date
    02-12-2012
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    3

    Code: return the color index of a colored cell

    Hi,
    I need a code, which would enable me to return the color index of a colored cell (colored via conditional formatting). If there is a colored reference cell, return the respective color index in next cell. I use Excel 2007. I need it only for four colors – red, blue, yellow and green. If the cell is not colored, return 0. I have tried some code, which is out on the net, without success, it does not work.
    Thank you very much!

  2. #2
    Valued Forum Contributor
    Join Date
    03-13-2004
    Location
    Gothenburg/Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and reluctantly Excel 2007
    Posts
    631

    Re: Code: return the color index of a colored cell

    Perhaps something like this?

    Option Explicit
    
    Sub find_col()
    
    Dim i As Integer
    
    
    i = ActiveCell.Interior.ColorIndex
    
    End Sub
    Alf

  3. #3
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,251

    Re: Code: return the color index of a colored cell


  4. #4
    Valued Forum Contributor dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    New Delhi, India
    MS-Off Ver
    Excel 1997, 2000, XP, 2003, 2007, 2010
    Posts
    2,406

    Re: Code: return the color index of a colored cell

    Hi Dpopov,

    Welcome to the forum.

    See the attached file where I have created a UDF (Vb function) to achieve the desired results.
    Also, below are the color codes which you require, else formula will say either it is No color / different color.
    Color Codes
    ------------
    Red = 3
    Blue = 23
    Yellow = 6
    Green= 14


    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    Attached Files Attached Files
    DILIPandey
    +919810929744
    dilipandey@gmail.com

  5. #5
    Registered User
    Join Date
    02-12-2012
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Code: return the color index of a colored cell

    Hi DILIPandey,
    Thank you a lot. I will try it out tomorrow. I am sure it will work.
    Regards,
    dpopov

  6. #6
    Registered User
    Join Date
    02-12-2012
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Code: return the color index of a colored cell

    Alf,
    thank you for the code. I will see if it works.
    Regards,
    dpopov

  7. #7
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,251

    Re: Code: return the color index of a colored cell

    Quote Originally Posted by dilipandey View Post
    Hi Dpopov,

    Welcome to the forum.

    See the attached file where I have created a UDF (Vb function) to achieve the desired results.
    Also, below are the color codes which you require, else formula will say either it is No color / different color.
    Color Codes
    ------------
    Red = 3
    Blue = 23
    Yellow = 6
    Green= 14


    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    He said ... coloured by conditional formatting.

  8. #8
    Valued Forum Contributor dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    New Delhi, India
    MS-Off Ver
    Excel 1997, 2000, XP, 2003, 2007, 2010
    Posts
    2,406

    Re: Code: return the color index of a colored cell

    Hi Bob,


    You are correct.. there is difference between coloring manually and coloring by conditional format...

    Dpopov, see the below link:-
    http://www.cpearson.com/excel/CFColors.htm

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey
    +919810929744
    dilipandey@gmail.com

  9. #9
    Forum Guru Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    MS Excel 2010
    Posts
    2,251

    Re: Code: return the color index of a colored cell

    Quote Originally Posted by dilipandey View Post
    Hi Bob,

    You are correct.. there is difference between coloring manually and coloring by conditional format...
    I know, that is why I gave the link that I did.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0