Pivot Table source data range (VBA)

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
I'm so annoyed. I have tried numerous attempts at this using code others have posted and this simply won't work.

I'm simply trying to adjust my data range for a pre-existing pivot table to include the appropriate range. I have hard-coded the range (I was using variables for the rows but nothign works so i gave up). Even this code, with a defined data range, doesn't work:

Code:
Sheets("Other Projects Detail").PivotTables("PivotTable1").SourceData = Sheets("ET").Range("J1:AO820").Address(True, True, xlR1C1, True)

I've tried other variations but keep getting a "Run time error 9: Subscript out of range error", but I really think the code should work. If I update the pivot table manually with this data range it works fine, so I don't think its the pivot table itself that's the issue.

I assume I'm missing something easy in my code, but can't see what it is.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
try:
Code:
= "ET!" & Range("J1:AO820").Address(True, True, xlR1C1, False)
 
Upvote 0
Jay, the range listed in the code is the new range. The pivot in the template is set to a different range.
 
Upvote 0
GlennUK, I tried your fix but it agve a different error (that to be honest closed down my Excel so I'm going to keeop playing with things with the "Sheets("ET")> syntax)
 
Upvote 0
Actually, I just tried changing the sheet name itself and then the sheetname in the code and it worked, so maybe something just got hung up and it didn't liike the sheetname. Regardless, it works now.
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,820
Members
452,946
Latest member
JoseDavid

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