Selecting a Chart series by name and then formatting

iepritchard

Board Regular
Joined
Jan 9, 2009
Messages
52
Hi All,

I have a chart on a chart sheet ("Chart2"), and the data on a separate sheet ("Sheet3"). I have multiple series plotted on the chart, but I also will plot All the data and name the series "All" (It will also be the last series). For this series I would like to not show the data markers but I do wish to show a trend line for the series. My main problem at the moment is that I can't select the "All" series on which to perform the formatting..?? The code I have at the moment is...

Sub Graph_Format()

Dim serColl As SeriesCollection
Set serColl = Charts(1).SeriesCollection

serColl(Count).Select

With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
Selection.Trendlines.Add(Type:=xlLogarithmic, Forward _
:=0, Backward:=0, DisplayEquation:=True, DisplayRSquared:=True).Select
Selection.Trendlines(1).DataLabel.Select
Selection.Left = 442
Selection.Top = 194

End Sub


Any suggestions..??!

Thanks,
Ian
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Is it?

Code:
    Dim ser As Series
    With Charts(1)
        Set ser = .SeriesCollection(.SeriesCollection.Count)
    End With
    ser.Select
 
Upvote 0

iepritchard

Board Regular
Joined
Jan 9, 2009
Messages
52
Recording I get..

Sheets("Chart2").Select
ActiveChart.SeriesCollection(14).Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
With Selection
.MarkerBackgroundColorIndex = xlNone
.MarkerForegroundColorIndex = xlAutomatic
.MarkerStyle = xlNone
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.SeriesCollection(14).Trendlines.Add(Type:=xlLogarithmic, Forward _
:=0, Backward:=0, DisplayEquation:=True, DisplayRSquared:=True).Select
End Sub

where series 14 is the last series.
 
Upvote 0

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
So this should work:

Code:
    Sheets("Chart2").Select
    With ActiveChart
        .SeriesCollection(.SeriesCollection.Count).Select
    End With
 
Upvote 0

Forum statistics

Threads
1,196,014
Messages
6,012,860
Members
441,737
Latest member
bijayche

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top