Changing trendline color and weight

B

biosci

I need to use VBA code to change the color and the thickness of
trendlines in a chart I generated using VBA. For the life of me I
cannot generate working code to change these trendline properties.
Surely this can be done. If someone could help me out it would be
greatly appreciated.
 
P

Peter T

Sub test()
Dim cht As Chart
Dim sr As Series
Dim tr As Trendline

Set cht = ActiveSheet.ChartObjects(1).Chart
Set sr = cht.SeriesCollection(1)
Set tr = sr.Trendlines(1)

tr.Border.ColorIndex = 3
tr.Border.LineStyle = xlDash 'xlContinuous
tr.Border.Weight = xlThick ' xlThin

End Sub

Regards,
Peter T
 
G

Guest

Formating the trendline's border is what you're looking for I believe:

Sub Test()
Dim cht As Chart
Set cht = ActiveSheet.ChartObjects(1).Chart
With cht.SeriesCollection(1).Trendlines(1).Border
.ColorIndex = 3
.Weight = xlThin
.LineStyle = xlContinuous
End With
End Sub

Regards,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top