VBA Code - Update Pivot Chart Source with Variable Row

Angela1982

New Member
Joined
Oct 16, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am still fairly new to VBA. I have been using S & LRGLOBAL throughout the rest of my Macros and would like to also use it for updating my pivotchart sources. However, I can't get it to update the chart even if I name it "S266", so I think it may be another part of the code that is stopping it from working. Any advice, please?

Sub Pivot_Tables()
'
' Pivot_Tables Macro
'
Sheets("GlobalListings").Select
Dim LRGLOBAL As Long
'For understanding LRGLOBAL = Last Row
LRGLOBAL = Cells(Rows.Count, 1).End(xlUp).Row

Sheets("Leahs Dashboard").Select

Charts(Global_PieChart).SetSourceData Source:=Sheets(GlobalListings).Range("A1:S" & LRGLOBAL)


End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Give this a try:

VBA Code:
Sub Pivot_Tables()
'
' Pivot_Tables Macro
'
Sheets("GlobalListings").Select
Dim LRGLOBAL As Long
'For understanding LRGLOBAL = Last Row
LRGLOBAL = Cells(Rows.Count, 1).End(xlUp).Row

Dim GlobalRng As Range
Set GlobalRng = Range("A1:B" & LRGLOBAL)

Sheets("Leahs Dashboard").Select
ActiveSheet.ChartObjects("Global_PieChart").Chart.SetSourceData Source:=GlobalRng

End Sub
 
Upvote 0
Thanks Alex, the code still stops at the ActiveSheet.ChartObjects line and I can't figure out why. I tried to record myself updating the chart as well. Every time I do, it only will not record the update.source command. This is all it shows: after I have stopped recording:

Sub Testing3()
'
' Testing3 Macro
'

'
ActiveSheet.ChartObjects("Global_PieChart").Activate
ActiveChart.FullSeriesCollection(1).Select
End Sub

I once had a version of excel that refused to recognize the Range.AutoFilter code. Could something like that be my issue?
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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