VBA to reset existing charts with column data from another sheet and rename legend

rebaS

New Member
Joined
Jun 26, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I would greatly appreciate your help with charts. I'm new to VBA and I just don't understand how to apply information from other posts to my issue.
I have 3 line charts and 3 column charts on Sheet 1. The data on sheet 2 is by month and updated monthly; therefore, the number of rows change month to month (e.g. Feb, Mar, April). The dates are in column A, starting in row 6. My charts never update and I have to manually "Select Data" each month. I would like the charts to auto update based on the data on sheet 2.

This is my latest attempt.

VBA Code:
Sub ResetCharts()
Dim cht As ChartObject
Dim wsData As Worksheet
Dim wsCharts As Worksheet
Dim lastRow As Integer
Dim i As Integer

Set wsData = daily
Set wsCharts = dash

lastRow = wsData.Cells(Rows.Count, 1).End(xlUp).Row

For i = 1 To wsCharts.ChartObjects.Count
Set cht = wsCharts.ChartObjects(i)
cht.Chart.SetSourceData Source:=wsData.Range("A6:C" & lastRow)
cht.Chart.FullSeriesCollection(1).Name = "aa"
cht.Chart.FullSeriesCollection(2).Name = "bb"
cht.Chart.Axes(xlCategory).CategoryType = xlCategoryScale
Next i
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Could you share a copy of your workbook via DropBox, Google Drive or similar file sharing platform? You can easily disguise any sensitive information.
 
Upvote 0
I apologize for taking so long to get back to you.
 
Upvote 0
@rebaS
Can you please confirm whether this is an Excel question or a Google Sheets question?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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