Isso deve funcionar quando você colá-lo em Developer -> Visual Basic
, embaixo da planilha em que você está trabalhando. Lembre-se de alterar o intervalo.
Sub Worksheet_Change(ByVal Target As Range)
Set Rng = Range("A1:B2")
If Application.Intersect(rng1, rng2) Is Not Nothing Then
Dim Min, Max, Index As Double
Dim Red, Green As Integer
Dim Cell As Range
Dim Rng As Range
Min = Minimum(Rng)
Max = Maximum(Rng)
For Each Cell In Rng
Index = (Cell.Value - Min) / (Max - Min)
Red = 255 * ListMin(1, 2 - 2 * Index)
Green = 255 * ListMin(1, 2 * Index)
Cell.Offset(RowOffset, ColumnOffset).Interior.Color = RGB(Red, Green, 0)
Next Cell
End If
End Sub
Function Maximum(Cells As Range)
Maximum = Application.WorksheetFunction.Max(Cells)
End Function
Function Minimum(Cells As Range)
Minimum = Application.WorksheetFunction.Min(Cells)
End Function
Function ListMax(ParamArray Values() As Variant)
ListMax = Application.WorksheetFunction.Max(Values)
End Function
Function ListMin(ParamArray Values() As Variant)
ListMin = Application.WorksheetFunction.Min(Values)
End Function
A maior parte disso deve ser bastante autoexplicativa, sinta-se à vontade para comentar se tiver alguma pergunta.