Solved

find out if a cell has yellow fill

Posted on 2016-11-01
8
36 Views
Last Modified: 2016-11-03
i need a formula to test if a cell has been filled with yellow.

any ideas?
0
Comment
Question by:finnstone
8 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41869279
In the Immediate window of Visual Basic, type

?Range("A1").interior.color ' Change A1to the address of a yellow cell

That will return a 6 to 8 digit number and you can use that number when looking at other cells.
0
 
LVL 13

Expert Comment

by:frankhelk
ID: 41869979
The tip to the Range().Interior.Color property is basically correct, here's just some clarification:

The returned value is the value returned by the RGB()  function for the respective color, and it consists of the values for Red, Green and Blue in that color. The help for RGB() shows some examples for that, and "classic" Yellow is defined as RGB(255,255,0) or 65535.

Internal it's represented as a 3 Byte integer value, where the right byte (the least significant) represents red, the middle one represents green, and the right one (the most significant) represents blue.

RGB(255,0,0) = 255 = Red
RGB(0,255,0) = 65280 = Green
RGB(0,0,255) = 16711680 = Blue
RGB(0,0,0) = 0 = Black
RGB(255,255,255) = White = 16777215

With that in mind, the minimum length of that number is 1 (for values ranging from 0 (Black) to 8 (an almost invisible faint red).

To check for a yellow cell, the statement would be
if Range(address).Interior.Color = RGB(255,255,0) then (...)

Open in new window

0
 
LVL 31

Expert Comment

by:Rob Henson
ID: 41870104
As far as I know it is not possible in standard formulas. You could possibly use a User Defined Function (UDF) which is basically a Visual Basic script that is triggered in the same way as a formula.

Alternatively, looking at it differently, is there a quantifiable reason why a cell would be coloured yellow?
Could that reason for the colour be converted to a Conditional Format so that a cell will automatically go yellow when a condition is met? If that were the case, you could then test for the condition that triggers the format rather than testing for the format itself.

Thanks
Rob H
0
 

Author Comment

by:finnstone
ID: 41872045
what can i type in excel to make any of these work?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:frankhelk
ID: 41872095
The most easy way is a user defined function. Open the VBA editor, insert a new module and paste the following code into:

Public Function IsCellYellow(r As Range) As Variant

    If r.Cells.Count > 1 Then
        IsCellYellow = CVErr(xlErrRef)
        Exit Function
    End If
        
    IsCellYellow = r.Interior.Color = RGB(255, 255, 0)

End Function

Open in new window


Use as explained in the attached example workbook.

The function allows a reference to exactly 1 cell and checks if the background is yellow. The result is returned as boolean (true/false). If more than 1 cell is referenced, an Excel error is returned. The function could be used at any place where a boolean value is allowed (i. e. IF(), IIF(), .... )

Hope that helps.
0
 
LVL 13

Accepted Solution

by:
frankhelk earned 500 total points
ID: 41872104
P.S.: To provide more amusement to the crowd, here's the luxury version of the function, which allows to check for any desired color:

Public Function IsCellColor(r As Range, Red As Integer, Green As Integer, Blue As Integer) As Variant

    If r.Cells.Count > 1 Then
        IsCellYellow = CVErr(xlErrRef)
        Exit Function
    End If
    
    If (Red < 0) Or (Red > 255) _
        Or (Green < 0) Or (Green > 255) _
        Or (Blue < 0) Or (Blue > 255) Then
        IsCellYellow = CVErr(xlErrValue)
        Exit Function
    End If
            
    IsCellYellow = r.Interior.Color = RGB(255, 255, 0)

End Function

Open in new window


Should be mostly self-explaining ...  ;-)
0
 

Author Comment

by:finnstone
ID: 41872108
thank you!
0
 
LVL 13

Expert Comment

by:frankhelk
ID: 41872119
Oops - mea maxima culpa ... I've made a quick shot and produced an error ... it takes arguments but still checks for yellow. The function should read

Public Function IsCellColor(r As Range, Red As Integer, Green As Integer, Blue As Integer) As Variant

    If r.Cells.Count > 1 Then
        IsCellYellow = CVErr(xlErrRef)
        Exit Function
    End If
    
    If (Red < 0) Or (Red > 255) _
        Or (Green < 0) Or (Green > 255) _
        Or (Blue < 0) Or (Blue > 255) Then
        IsCellYellow = CVErr(xlErrValue)
        Exit Function
    End If
            
    IsCellYellow = r.Interior.Color = RGB(Red, Green, Blue)

End Function

Open in new window


( Just 1 line changed, the final test ...)

And here's the promised example workbook, too: Example.xlsm
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now