VBA to Change Elements of Chart's Data Source

bisel

Board Regular
Joined
Jan 4, 2010
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Greetings All,

I generally try recording macros to review the VBA code that I can use when creating new macros. Am stumped on this situation.

I have a chart with several data elements. I want to provide the abillity using a command button so that a user can toggle between the inclusion of two data elements. For example, here is screen shot of the "Select Data" table of the chart in question ...

1594423018400.png


I want to have a command button that unchecks one of the boxes circled above and checks the other. But, when I record my macros, this is the result ...

VBA Code:
Sub toggledata()

    ActiveSheet.ChartObjects("reserve_contrib_chart").Activate
    ActiveChart.PlotArea.Select
    ActiveChart.ChartArea.Select
    ActiveChart.PlotArea.Select

End Sub

Appreciate any suggestions.

Steve
 

Attachments

  • 1594422973251.png
    1594422973251.png
    32.3 KB · Views: 7

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try something like this (not tested), you need to change object names.

VBA Code:
Sub ChangeChartSeries()

    Dim MySeries As Series
    ActiveSheet.ChartObjects("reserve_contrib_chart").Activate

    For Each MySeries In ActiveChart.SeriesCollection
        Select Case MySeries.Name 'Use the Select Case so you can add more options
            Case "NotThisSeries" 'Change the object name
              ActiveChart.SeriesCollection(MySeries.Name).IsFiltered = True
        End Select
    Next MySeries

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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
Back
Top