Sean Lauber:Heat maps in Excel

From OpenWetWare
Revision as of 07:38, 26 October 2012 by Sean E. Lauber (talk | contribs) (New page: Use the following macro: Sub heatmap() Dim myrange As Range Dim colchoice As Integer Set myrange = Application.InputBox("Select a range of cells", rangetocheck, , , , , , 8) For...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Use the following macro:

 Sub heatmap()
 Dim myrange As Range
 Dim colchoice As Integer
 Set myrange = Application.InputBox("Select a range of cells", rangetocheck, , , , , , 8)
 For Each cell In myrange
 Select Case cell.Value
 Case Is >= 8
    colchoice = 1
    fontchoice = 2
 Case Is >= 7
    colchoice = 3
 Case Is >= 6
    colchoice = 45
 Case Is >= 5
    colchoice = 6
 Case Is >= 4
    colchoice = 19
 Case Is >= 3
    colchoice = 20
 Case Is >= 2
    colchoice = 8
 Case Is >= 1
    colchoice = 41
 Case Is < 0
    colchoice = 5
    fontchoice = 2
 End Select
 cell.Interior.ColorIndex = colchoice
 cell.Font.ColorIndex = fontchoice
 fontchoice = 1
 Next
 End Sub