Excel VBA Change color of gradient fill

Hi

I use the following code to add a two color gradient fill to the chart.
The color is maroon. How would I alter the code to use blue instead.
I used the macro recorder and the code seemed to be all the same.
What governs the color of the fill

Sub Macro2()
'
' Macro2 Macro

    With ActiveSheet.Shapes("Chart 1").Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent1
        .ForeColor.TintAndShade = 0.3399999738
        .ForeColor.Brightness = 0
        .BackColor.ObjectThemeColor = msoThemeColorAccent1
        .BackColor.TintAndShade = 0.7649999857
        .BackColor.Brightness = 0
        .TwoColorGradient msoGradientVertical, 2
        .RotateWithObject = msoTrue
    End With
End Sub
Image1.png
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
I'm assuming you are setting the two gradient color.. and it's this line which is controlling the same...

.TwoColorGradient msoGradientVertical, 2

Open in new window


Saurabh...
0
ProfessorJimJamCommented:
here you go

change the numbers RGB(0, 0, 255)  to the desired color Color Palette

Sub test()
Dim oFill As FillFormat
    Set oFill = ActiveSheet.Shapes(1).Fill
    With oFill
        .TwoColorGradient msoGradientHorizontal, 1
        With .GradientStops(1)
            .Color = RGB(0, 0, 255)
            .Position = 0
            .Transparency = 0
        End With
        With .GradientStops(2)
            .Color = RGB(0, 0, 255)
            .Position = 1
            .Transparency = 0
        End With
        .GradientStops.Insert RGB:=RGB(0, 0, 255), Position:=0.5, Transparency:=0
        .Visible = msoTrue
    End With

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.