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>
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,899
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
 

Forum statistics

Threads
1,082,258
Messages
5,364,093
Members
400,779
Latest member
lumers

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top