Function AddShape(CellValue As Range) As String
Dim MyRange As Range
Dim MyShape As Shape
Dim TopColor As Long, BottomColor As Long
Set MyRange = Application.Caller
'Remove any previous shapes
DeleteShape CellValue
'Make sure CellValue has a value
If CellValue.Value = 0 Then
Exit Function
End If
'This is the logic that determines the two colors based
'on the value in CellValue
Select Case CellValue
Case Is < 10
TopColor = vbGreen
BottomColor = vbGreen
Case Is < 15
TopColor = vbGreen
BottomColor = vbYellow
Case Is < 20
TopColor = vbYellow
BottomColor = vbYellow
Case Is < 30
TopColor = vbYellow
BottomColor = vbRed
Case Else
TopColor = vbRed
BottomColor = vbRed
End Select
'Now create the two shapes
With MyRange.Worksheet.Shapes
Set MyShape = .AddShape(msoShapeRightTriangle, MyRange.Left, MyRange.Top, MyRange.Width, MyRange.Height)
With MyShape
.Name = "shp" & CellValue.Address & "b"
.Fill.ForeColor.RGB = BottomColor
.Locked = True
End With
Set MyShape = .AddShape(msoShapeRightTriangle, MyRange.Left, MyRange.Top, MyRange.Width, MyRange.Height)
With MyShape
.Name = "shp" & CellValue.Address & "t"
.Fill.ForeColor.RGB = TopColor
.Rotation = 180
End With
End With
AddShape = ""
End Function
Sub DeleteShape(ThisCell As Range)
Dim ThatShape As Shape
For Each ThatShape In ThisCell.Worksheet.Shapes
If ThatShape.Name Like "shp" & ThisCell.Address & "*" Then
ThatShape.Delete
End If
Next
End Sub