Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I find colored cells?

Best of Excel

How can I find colored cells?

by  SkipVought  Posted    (Edited  )
The short answer is, you can't!

Where you can enter a formula and determine if a cell contains a certain value, there is no forumla that can do a similar thing for a certain format.

However, all is not lost. Help is on the way! This is a User Define Function (UDF) that can return a string, reflecting the cell interior color for the colors Red, Blue, Green, Yellow, White, Black, Magenta & Cyan.

Paste it in a Module. It would be good to put it in your PERSONAL.XLS workbook. Then, use it like any other function on your worksheet like this...
[tt][highlight yellow]
=IF(WhatInteriorColor(A1)="Red","I got RED!","nada")
[/highlight][/tt]
Code:
[blue]
Function WhatInteriorColor(rng As Range) As String
'Skip Metzger - 2007 May 29
'this function returns the color of the interior of a given cell
'
    Select Case rng.Interior.Color
        Case vbBlack
            WhatInteriorColor = "Black"
        Case vbRed
            WhatInteriorColor = "Red"
        Case vbGreen
            WhatInteriorColor = "Green"
        Case vbYellow
            WhatInteriorColor = "Yellow"
        Case vbBlue
            WhatInteriorColor = "Blue"
        Case vbMagenta
            WhatInteriorColor = "Magenta"
        Case vbCyan
            WhatInteriorColor = "Cyan"
        Case Else
            Select Case rng.Interior.ColorIndex
                Case 2
                    WhatInteriorColor = "White"
                Case xlColorIndexNone
                    WhatInteriorColor = "None"
                Case Else
                    WhatInteriorColor = "Other"
            End Select
    End Select
End Function
[/blue]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top