Is it possible to write an IF statement that returns a value in a cell, if another cell is coloured yellow and red?

Sampoline

New Member
Joined
Dec 2, 2020
Messages
24
Office Version
  1. 2013
Platform
  1. Windows
I have some rows that are coloured in yellow or red and other rows with no fill or a different colour. I only want the yellow and red rows to return a value.

When a row has a red or yellow fill, I have a separate column that should return a value (for example: "Y"). If not yellow or red, it should leave that cell blank.

Is this possible? Perhaps VBA if required? See below for example of what I mean:

1606958907282.png
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
This UDF will determine the interior color of a cell:

Code:
Function getColor(Rng As Range, ByVal ColorFormat As String) As Variant
    Dim ColorValue As Variant
    ColorValue = Cells(Rng.Row, Rng.Column).Interior.Color
    Select Case LCase(ColorFormat)
        Case "index"
            getColor = Rng.Interior.ColorIndex
        Case "rgb"
            getColor = (ColorValue Mod 256) & ", " & ((ColorValue \ 256) Mod 256) & ", " & (ColorValue \ 65536)
        Case Else
            getColor = "Only use 'Index' or 'RGB' as second argument!"
    End Select
End Function

That should help you define your IF statement doing something like: =getColor(A2,"index") and testing that for the value in question.
OR:
Code:
=IF(OR(3=GetColor(A2,"Index"),6=GetColor(A2,"index")),"Y","")
 
Upvote 0
Solution
This UDF will determine the interior color of a cell:

Code:
Function getColor(Rng As Range, ByVal ColorFormat As String) As Variant
    Dim ColorValue As Variant
    ColorValue = Cells(Rng.Row, Rng.Column).Interior.Color
    Select Case LCase(ColorFormat)
        Case "index"
            getColor = Rng.Interior.ColorIndex
        Case "rgb"
            getColor = (ColorValue Mod 256) & ", " & ((ColorValue \ 256) Mod 256) & ", " & (ColorValue \ 65536)
        Case Else
            getColor = "Only use 'Index' or 'RGB' as second argument!"
    End Select
End Function

That should help you define your IF statement doing something like: =getColor(A2,"index") and testing that for the value in question.
OR:
Code:
=IF(OR(3=GetColor(A2,"Index"),6=GetColor(A2,"index")),"Y","")
Thankyou so much kweaver! This worked like a charm :love:
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top