Conditional Formatting Macro

Gronk_h8er

Board Regular
Joined
Jan 6, 2009
Messages
63
Hi,

I am trying to put together a heat map in excel 2003 and need to have more than 3 conditions. Therefore i need to use VBA.

For my range of cells F2:AL200, i need all cells that contain "U" to be red, all cells that contain "S" to be bright green and all cells that contain "" to be grey.

I have downloaded a macro from the web and tried to adjust it for my needs, but it doesn't seem to be working.

Please find it below...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer

If Not Intersect(Target, Range("F2:AL200")) Is Nothing Then
Select Case Target
Case Is = "U"
icolor = 3
Case Is = "S"
icolor = 4
Case Is = ""
icolor = 15
Case Else
'Whatever
End Select

Target.Interior.ColorIndex = icolor
End If

I am not proficient enough at VBA to figure out were i am going wrong so any help will be appreciated.

Also, while i am here...On a another sheet i want to create a similar heat map except now the conditions are numbers.

I need all numbers greater than 1 to be dark blue, all numbers that equal 1 to be light blue, all numbers that equal 0 to be green, all numbers that are equal to -1 to be orange and all numbers less than -1 to be red.

Thanks.
 
Thanks so much Stan!

Works perfectly!

I really appreciate the level of effort people will put in for complete strangers just to help them out! This is a really great community!

Cheers.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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