Sub ColorMe()
VerticalDataBar Selection, 14922893 'Vertical gradient color bars in powder blue
End Sub
Sub VerticalDataBar(rg As Range, lngColor As Long)
Dim dMin As Double, dMax As Double, dRange As Double, dScale As Double
Dim dHigh As Double, dWide As Double
Dim shp As Shape
Dim cel As Range
On Error Resume Next
dMin = 0 'Scale the heights from a starting point of 0
'dMin = Application.Min(rg) 'Scale the heights from the smallest value
dMax = Application.Max(rg)
dRange = dMax - dMin
dHigh = rg.RowHeight
dWide = dHigh
With rg.Worksheet
For Each cel In rg.Cells
Set shp = Nothing
Set shp = .Shapes("VDataBar" & cel.Address)
If Not shp Is Nothing Then shp.Delete
If IsNumeric(cel) Then
dScale = dHigh * (cel.Value - dMin) / dRange
With .Shapes.AddShape(msoShapeRectangle, cel.Left, cel.Top + cel.RowHeight - dWide, dWide, dWide)
.Name = "VDataBar" & cel.Address
.Fill.ForeColor.RGB = lngColor
.Fill.OneColorGradient msoGradientVertical, 1, 1
.Line.Visible = msoFalse
.Rotation = 270
.Width = dScale
End With
End If
Next
End With
On Error GoTo 0
End Sub
|