Change Pivot connections with vba

RSBaidoo

New Member
Joined
Jun 10, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi colleagues,
Source connection to my pivots are all queried data but anytime i change the one of the pivot table connection the other pivots connection does not change.

I tried recording a macro whilst changing the connection of the pivot table but this looks tedious since i have to change the pivot table names manually in the codes.

Please how can I use vba to change the connection to the pivots once so that all the pivots will is linked to one connection and refreshes anytime one first pivot is refreshed.

Thank you
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
When you say queried data what exactly do you mean?

Is it possible to load the query into PowerPivot and use that as the Pivot data source?

The other option would be to maybe run a macro on pivot change for a pivot that will then loop through all others. Trick there being not retriggering that macro into an endless loop.

I'd use the first option if possible personally.
 
Upvote 0
Solution
Thank you very much for the insight

I tried the second option which is running a macro on the pivot that will loop through the others.
And it gives me run-time error saying "Object variable of With block variable not set"

This is the coding I did...

1623409882162.png


Grateful for your help!
 
Upvote 0
I'm not back in front of a PC for a few days so I'm not sure on the exact syntax needed here.

What's the result when you record a macro and change the query?
 
Upvote 0
After recording and changing the query it worked perfectly

But having a run time error after inculcating the loop

This is the macro i recorded

1623667651184.png
 
Upvote 0
What does it all look like together and where abouts is it giving the error, and which error.

Pasting in the code would help instead of a screenshot to try and replicate the issue. Cheers
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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