GetPivotData getting #REF error while worksheet is being replaced in VBA

ninaking

New Member
Joined
Jun 5, 2011
Messages
15
Hello,

I've created a PivotTable with VBA which works fine. The problem is that when I delete and create a new pivottable on a new worksheet to update the values, all of my formulas on an existing worksheet end up with the #REF error.

I need to reference this PivotTable to do a VLookup of User Name to retrieve the correct values to update another table. So my formula is: =GETPIVOTDATA("Count Of Fruits",User_Name_PivotTable,"Segment","Fruits","User Name",A2)

The User_Name_PivotTable is a named range that refers to the ResultsPivotTable worksheet that's getting deleted and replaced with the new data.

WorksheetName: ResultsPivotTable
User_Name_PivotTable is a defined name which refers to: ResultPivotTable!$A$1

How do I keep my GetPivotData function from filling with errors while I'm creating the new worksheet with the same name? Or is there a better way to do this? I have to do all of it automatically as my users are not excel-proficient at all. Please help!!
User_Name (A1)
Fruits (B1)
Vegetables (C1)
John
10
25
Jack
15
30

<tbody>
</tbody>
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
the #ref is because you are deleteing the pivot table, if you can get it to refresh wit the new data then that should no longer be the issue

If you can't then the only way i know is to use vba to rebuild the formuals as part of the routine
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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