View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Trendline color format bug/issue?

There are various reasons why the following might not work correctly for you
but see how you get on.

Sub change_trendlines()
'Dim mysrcolor As ColorFormat, myset As ColorFormat
Dim ch1 As ChartObject
Dim series1 As Series
Dim trend1 As Trendline
'Dim myline As LineFormat
Dim n As Long

' assumes ALL Line type series in ALL charts

For Each ch1 In ActiveSheet.ChartObjects
n = 24
For Each series1 In ch1.Chart.SeriesCollection
If n = 56 Then n = 0
n = n + 1
cx = series1.Border.ColorIndex
If cx = xlAutomatic Then cx = n

For Each trend1 In series1.Trendlines

With trend1.Border
.LineStyle = msoLineDash
.Weight = 2
.ColorIndex = cx
End With

Next trend1
Next series1
Next ch1

End Sub

Regards,
Peter T

"satishbhave" wrote in message
...
I want to change the trendlines color/type/width to match the data series
line color. i have this vb code which works well and changes type and

width
but not color. what i found was that to make this work, first, i need to
manually change the color of trendlines and then run the macro.. i don;t

know
if this is a bug or something i am not doing properly

Sub change_trendlines()
Dim mysrcolor, myset As ColorFormat
Dim ch1 As ChartObject
Dim series1 As Series
Dim trend1 As Trendline
Dim myline As LineFormat


For Each ch1 In ActiveSheet.ChartObjects
ch1.Activate
For Each series1 In ActiveChart.SeriesCollection
Set mysrcolor = series1.Format.Line.ForeColor
For Each trend1 In series1.Trendlines
Set myline = trend1.Format.Line
myline.DashStyle = msoLineDash
myline.Weight = 2
myline.ForeColor.RGB = mysrcolor.RGB
Next trend1
Next series1
ch1.Activate
Next ch1

End Sub

any help on this is highly appreciated