Vba for 5 cond format in a range

Spraggs

Well-known Member
Joined
Jan 19, 2007
Messages
704
Hello All,
I'm after some Vba because I require five conditional formats and I'm working with excel 2003.

My range is C3:BJ37 and cell H43 (Sheet1)

Conditions..
1. <=420 Colour Red
2. <=840 Colour Orange
3. <=1260 Colour Yellow
4. <=1680 Colour Light Green
5. <=21000 Colour Bright Green

(Colours not too important)

Is this possible.

Any help is appreciated.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
VoG
Now this works a treat is it possible to add something else....
Any cell between C3:BJ37 that is equal to cell H43 to have a diagonal border (e.g. X). I could create a simple macro if need be to change a cell and then return it to original value if this is required to trigger change.

Regards Jase
 
Upvote 0
Try

Code:
Private Sub Worksheet_Calculate()
With Range("H43")
    Select Case .Value
        Case Is <= 420: .Interior.ColorIndex = 3
        Case Is <= 840: .Interior.ColorIndex = 44
        Case Is <= 1260: .Interior.ColorIndex = 6
        Case Is <= 1680: .Interior.ColorIndex = 43
        Case Is <= 21000: .Interior.ColorIndex = 4
    End Select
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
For Each c In Range("C3:BJ37")
    Select Case c.Value
        Case Is <= 420: c.Interior.ColorIndex = 3: c.Font.ColorIndex = 3
        Case Is <= 840: c.Interior.ColorIndex = 44: c.Font.ColorIndex = 44
        Case Is <= 1260: c.Interior.ColorIndex = 6: c.Font.ColorIndex = 6
        Case Is <= 1680: c.Interior.ColorIndex = 43: c.Font.ColorIndex = 43
        Case Is <= 21000: c.Interior.ColorIndex = 4: c.Font.ColorIndex = 4
    End Select
    If c.Value = Range("H43").Value Then
        c.Borders(xlDiagonalDown).Weight = xlThin
        c.Borders(xlDiagonalUp).Weight = xlThin
    End If
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

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