98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA Turning white to blue in my code
VBA Turning white to blue in my code
Resolved · Low Priority · Version 2010
Emma has attended:
Excel VBA Introduction course
VBA Turning white to blue in my code
This code creates a gradient bar representing age volumes (from 0-100). I used rank to order 14 age groups, and assigned darker colours to the highest volume etc. It works fine, until you open the whole worksheet again. The last gradient stop (1) is a shade of blue, when it should always be white. Can this be fixed?
Sub Colour2()
Sheets("Profile").Select
Dim rng As Range
'Current Age
Set rng = Sheets("Profile").Range("B8")
rng.Cells.Merge
Dim grd1 As LinearGradient
rng.Interior.Pattern = XlPattern.xlPatternLinearGradient
Set grd1 = rng.Interior.Gradient
Dim cs As ColorStop
grd1.Degree = 0
' Add a color stop at 25% of the width:
Set cs = grd1.ColorStops.Add(Cells.Item(112, "F"))
cs.Color = RGB(3, 69, 85)
Set cs = grd1.ColorStops.Add(Cells.Item(113, "F"))
cs.Color = RGB(4, 88, 108)
Set cs = grd1.ColorStops.Add(Cells.Item(114, "F"))
cs.Color = RGB(4, 103, 126)
Set cs = grd1.ColorStops.Add(Cells.Item(115, "F"))
cs.Color = RGB(4, 112, 138)
Set cs = grd1.ColorStops.Add(Cells.Item(116, "F"))
cs.Color = RGB(5, 126, 155)
Set cs = grd1.ColorStops.Add(Cells.Item(117, "F"))
cs.Color = RGB(6, 142, 174)
Set cs = grd1.ColorStops.Add(Cells.Item(118, "F"))
cs.Color = RGB(7, 164, 201)
Set cs = grd1.ColorStops.Add(Cells.Item(119, "F"))
cs.Color = RGB(8, 178, 218)
Set cs = grd1.ColorStops.Add(Cells.Item(120, "F"))
cs.Color = RGB(8, 194, 238)
Set cs = grd1.ColorStops.Add(Cells.Item(121, "F"))
cs.Color = RGB(44, 209, 248)
Set cs = grd1.ColorStops.Add(Cells.Item(122, "F"))
cs.Color = RGB(88, 219, 250)
Set cs = grd1.ColorStops.Add(Cells.Item(123, "F"))
cs.Color = RGB(117, 225, 251)
Set cs = grd1.ColorStops.Add(Cells.Item(124, "F"))
cs.Color = RGB(154, 233, 252)
Set cs = grd1.ColorStops.Add(Cells.Item(125, "F"))
cs.Color = RGB(185, 240, 253)
' Add a color stop at 100% of the width:
Set cs = grd1.ColorStops.Add(1)
cs.Color = RGB(154, 254, 254)
End Sub
RE: VBA Turning white to blue in my code
Hi Emma
Interesting question. I noticed a difference by adding the line
grd1.ColorStops.Clear
just before your comment
' Add a color stop at 25% of the width:
This seems to keep the gradient colouring and not change it after closing and opening the file.
Also if you change the last line from
cs.Color = RGB(154, 254, 254)
to
cs.Color = RGB(254, 254, 254)
the last stop displays as white
Hope that helps.
Doug Dunn
Best STL
Mon 13 Apr 2015: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:ChartsSelect the data and press the function key F11 and the chart will be created on a separate worksheet. |