Pivot table refresh issue with SQL

jkchild

Board Regular
Joined
May 24, 2006
Messages
167
Hi

I have an excel file that updates 1 tab based on an sql program.

I then create a pivot table in a new tab.
When I refesh the sql, it removes the data and updates with new data in the same tab.

this means that when i refresh the pivot table it thinks I deleted the data and gives me an error, is there a way I can lock the pivot table range after the sql refresh??

thanks
J
 
if you make your sql dump a named range, then create your pivot from the named range that should work

Code:
    Workbooks(XXX).Names("AltRes").Delete

    Range("A1").Select
    AA = Range("a20000").End(xlUp).Row
    zy = "='VehicleKey'!R2C1:R" & AA & "C9"

    Workbooks(XXX).Names.Add Name:="AltRes", RefersToR1C1:=zy
 
Upvote 0
Mole's answer should be fine without any VBA. That is, just give the dataset a defined name, and make it the source data for the pivot table. The range of the name should adjust automatically each time the query is refreshed.
 
Upvote 0

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