VBA if function based on colors

lcaindoy

New Member
Joined
Jun 12, 2018
Messages
22
Hope you could help me.

I saw the below code in the internet, however, I don't know why it's not working for me.

Function CheckColor1(range)
If range.Interior.Color = RGB(256, 256, 0) Then
CheckColor1 = "***"
Else
CheckColor1 = ""
End If
End Function

Inputs:
1. I have set of data and one column (Let's say J column) has blank, yellow, and other colors in a set of range (J7 to J500)
2. I have tried the above formula but its not working.

Output:
1. Based on the color on each cell, I want to make a markings.
If yellow, it will note "***"
If other, it will be blank
2. output is on column K

Please let me know if you need further info.
 
Last edited:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Looks like it's doing what you want. Yellow = "**" otherwise no marking. Is that right?

(this is assuming RGB-256,256,0 is yellow), otherwise just try color 65535...

range.Interior.Color = 65535
 
Last edited:
Upvote 0
Looks like it's doing what you want. Yellow = "**" otherwise no marking. Is that right?

(this is assuming RGB-256,256,0 is yellow), otherwise just try color 65535...

range.Interior.Color = 65535

Hi JProffer,

No it's not working, I'm not so familiar with VBA.
What I try is after the above coding, On the cell where I want the output I used the =CheckCode1(Cell) but the output od this is #NAME ?. If I'm right when I type a formula shouldn't it show the checkcolor function as if it is sum function(just for example coz I'm not really sure how the function code in vba works)?
 
Upvote 0
#NAME means your function isn't being found. Where is the function located, and where is the worksheet you're trying to use it on?
 
Upvote 0
Is the function in the same workbook as the worksheet where you're using it? In a standard code module?
 
Upvote 0
If it's in the same workbook, it looks to me like it should work. The only change you might try is this:

Code:
Function CheckColor1(range as Range)
    If range.Interior.Color = RGB(256, 256, 0) Then
        CheckColor1 = "***"
    Else
        CheckColor1 = ""
    End If
End Function

(dimensioning the range variable passed to the function) Other than that, I can't imagine why it wouldn't work.
 
Upvote 0
If it's in the same workbook, it looks to me like it should work. The only change you might try is this:

Code:
Function CheckColor1(range as Range)
    If range.Interior.Color = RGB(256, 256, 0) Then
        CheckColor1 = "***"
    Else
        CheckColor1 = ""
    End If
End Function

(dimensioning the range variable passed to the function) Other than that, I can't imagine why it wouldn't work.

Do I need to change something in this code like the range?
 
Upvote 0
To me, it looks like it should work as it is. You would use it like:

=CheckColor1(A1)

and if A1 is yellow (again, assuming 256, 256, 0 is yellow) it should put "***" in the cell the formula is in, which I would assume would be B1.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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