BrianDP1977
Board Regular
- Joined
- Nov 5, 2005
- Messages
- 146
The following code is taken from a recorded macro that changes the displayed data on a chart after a button is clicked:
It works fine but I was wondering if there was a way to reformat it so the code was a little more succinct (i.e. get rid of the whole select thing and ActiveChart call and instead use a name ("Chart1") as the reference). If that's not possible, is there a way to at least make it so that the plot area on the chart isn't still selected after the macro runs?
Code:
Private Sub OptionButton2_Click()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).XValues = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_NL"
ActiveChart.SeriesCollection(1).Values = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_Depart"
ActiveChart.SeriesCollection(2).XValues = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_NL"
ActiveChart.SeriesCollection(2).Values = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_StrtS"
ActiveChart.SeriesCollection(3).XValues = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_NL"
ActiveChart.SeriesCollection(3).Values = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_StpS"
ActiveChart.SeriesCollection(4).XValues = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_NL"
ActiveChart.SeriesCollection(4).Values = _
"='Overview and Deployment Staff Slides (v22).xls'!Chart_T_DP6_CT"
End Sub
It works fine but I was wondering if there was a way to reformat it so the code was a little more succinct (i.e. get rid of the whole select thing and ActiveChart call and instead use a name ("Chart1") as the reference). If that's not possible, is there a way to at least make it so that the plot area on the chart isn't still selected after the macro runs?