Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

find out if a cell has yellow fill

Posted on 2016-11-01
8
Medium Priority
?
64 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 49

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 14

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 33

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:finnstone
ID: 41872045
what can i type in excel to make any of these work?
0
 
LVL 14

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 14

Accepted Solution

by:
frankhelk earned 2000 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 14

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
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 …

636 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