Vba code to color format cells depending on 3 outcomes

Alpacino

Well-known Member
Joined
Mar 16, 2011
Messages
511
Hi wondering what would the code be color cells in if
Values is 0 to 40 cell color red
41 to 60 yellow
61 to 100 green

I have used if then but it only uses the first 2 ifs.
Anyone help please.
Thanks
Alan
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Not sure if you want this to automatically run on a sheet selection change (clicking on a cell) or if you want to run it manually, but here is the basic code. Change the cell as needed.
Code:
    If Range("A18") <> "" Then
        Select Case Range("A18")
            Case 0 To 40
                Range("A18").Interior.ColorIndex = 3
                Range("A18").Interior.Pattern = xlSolid
            Case 41 To 60
                Range("A18").Interior.ColorIndex = 6
                Range("A18").Interior.Pattern = xlSolid
            Case 61 To 100
                Range("A18").Interior.ColorIndex = 4
                Range("A18").Interior.Pattern = xlSolid
            Case Else
                MsgBox "The number entered is not valid.", vbOKOnly, "Invalid Entry"
        End Select
    Else: End If
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,548
Members
452,927
Latest member
rows and columns

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