Help with Chart Macro.

Troy1

Board Regular
Joined
Jul 2, 2014
Messages
149
Excel 2010
Windows 7

Hello I have macro that I am trying to create that will do the following.

1. Select the chart on the tab. (there is only 1 chart named Chart 1)
2. Right click the chart and select "Select Data".
3. Remove series collect 1. (Which is removing the oldest month from the chart.)
4. Then add "Sept" series to the chart.
5. Have it use values of $AC$26:$AC$28 on the active sheet. (I cant figure out how to tell it to use that range on the active sheet).

But when I run the macro it does absolutely nothing!

Code:
Sub AddSeptFinal()'
' AddSeptFinal Macro
'


'
    
    ActiveSheet.Select
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(6).Name = "=""Sep"""
    ActiveChart.SeriesCollection(6).Values = "=CGO!$AC$26:$AC$28"
    Range("AM32").Select




End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Have you tried putting a breakpoint in your macro and stepping through it? How are you calling the macro? If from another macro have you set On Error Resume Next somewhere in it?
 
Upvote 0
The macro is its own sub routine. I have stepped through the macro, it appears that it is selecting the chart but not calling the "Select Data" function to allow it to remove seriescollection1 and adding seriescollection6. Basically the macro is just selecting the chart and then deselecting the chart.
 
Upvote 0
Your code worked for me when I tried it. I plotted W26:AB28 as six series. Running the macro deleted the first series (W6:W28) and added AC26:Ac28 as series 6.
 
Last edited:
Upvote 0
Hi Troy

Please try this (part of your) code and see if it does not delete the first series in the first chart:

Code:
Sub Test()
    
    ActiveSheet.ChartObjects(1).Activate
    ActiveChart.SeriesCollection(1).Delete

End Sub
 
Upvote 0
Hi Troy

Please try this (part of your) code and see if it does not delete the first series in the first chart:

Code:
Sub Test()
    
    ActiveSheet.ChartObjects(1).Activate
    ActiveChart.SeriesCollection(1).Delete

End Sub

Hey I tried this and it did not delete the first series. The macro appears to select the chart but then does nothing. I am not sure what is going on :(.
 
Upvote 0
Here I have uploaded an example spreadsheet.

Code:
https://drive.google.com/file/d/0B7ZAZgflZvezTkk2T19UdFZFWDg/edit?usp=sharing
 
Upvote 0
Try this link:

Code:
https://www.dropbox.com/s/ynva3rdr89026n5/Example%20Chart%20Macro.xlsx?dl=0
 
Upvote 0

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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