Case or If statement

eznsd

New Member
Joined
Oct 29, 2015
Messages
42
I have the following code to change a cell's color based on certain conditions. I am comparing the values of two cells on the same worksheet. I have tried this with If Else If, seperate If statements and Case statements but cannot get it to work. Any clues would be appreciated and Happy Holidays!
Code:
        Select Case value
            Case Range("N" & j).value = "0"
                Range("N" & j).Interior.Color = RGB(255, 0, 0)
                Range("N" & j).BorderAround Weight:=xlThin
                Range("N" & j).BorderAround xlContinuous
            Case Range("N" & j).value - Range("G" & j).value <= "100"
                Range("N" & j).Interior.Color = RGB(255, 192, 0)
                Range("N" & j).BorderAround Weight:=xlThin
                Range("N" & j).BorderAround xlContinuous
            Case Range("N" & j).value < Range("G" & j).value
                Range("N" & j).Interior.Color = RGB(255, 255, 0)
                Range("N" & j).BorderAround Weight:=xlThin
                Range("N" & j).BorderAround xlContinuous
        End Select
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Perhaps:-
Code:
Select Case Range("N" & J).Value
            Case Is = "0"
                Range("N" & J).Interior.Color = RGB(255, 0, 0)
                Range("N" & J).BorderAround Weight:=xlThin
                Range("N" & J).BorderAround xlContinuous
            Case Is <= "100"
                Range("N" & J).Interior.Color = RGB(255, 192, 0)
                Range("N" & J).BorderAround Weight:=xlThin
                Range("N" & J).BorderAround xlContinuous
            Case Is < Range("G" & J).Value
                Range("N" & J).Interior.Color = RGB(255, 255, 0)
                Range("N" & J).BorderAround Weight:=xlThin
                Range("N" & J).BorderAround xlContinuous
        End Select
 
Upvote 0
That would make too much sense! I will give it a try and let you know shortly. Thanks for the reply Mick and Happy Holidays!
 
Upvote 0
I wanted to let you know that I was able to modify your code and get it to work. This is the final code.
Code:
        Select Case Range("N" & j).value
            Case 0
                Range("N" & j).Interior.Color = RGB(255, 0, 0)
                Range("N" & j).BorderAround Weight:=xlThin
                Range("N" & j).BorderAround xlContinuous
            Case Is < Range("G" & j).value
                Range("N" & j).Interior.Color = RGB(255, 255, 0)
                Range("N" & j).BorderAround Weight:=xlThin
                Range("N" & j).BorderAround xlContinuous
            Case 1 To 100
                Range("N" & j).Interior.Color = RGB(255, 192, 0)
                Range("N" & j).BorderAround Weight:=xlThin
                Range("N" & j).BorderAround xlContinuous
        End Select
Thanks again for leading me in the right direction! Happy Holidays!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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