Macro to auto update Excel Chart

rastus

Board Regular
Joined
Jul 8, 2005
Messages
157
Hi

I am using this code to automatically update the data series in a chart based on the month (extract only):

Sub AddNewWorkedSeries()

If Range("I3").Value = "1" Then
With ActiveChart.SeriesCollection.NewSeries
.Name = "Worked"
.Values = Sheets("Sheet1").Range("B19:AF19")
.XValues = Sheets("Sheet1").Range("B4:AF4")
End With

End If
If Range("I3").Value = "2" Then
With ActiveChart.SeriesCollection.NewSeries
.Name = "Worked"
.Values = Sheets("Sheet1").Range("B20:AF20")
.XValues = Sheets("Sheet1").Range("B4:AF4")
End With

where I3 is the month of year ("1" = January, "2" = February, etc)

This works fine for a chart with only one Y-axis. But I have now been asked to add a second Y-axis to the same chart. The X-axis will remain unchanged.

Does anyone know how to modify this code so it only updates the data series for the second Y-axis without affecting the data series already updated for the first Y-axis?

Thanks

R
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,203,329
Messages
6,054,756
Members
444,748
Latest member
knowak87

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