How do I update pivot tables with visual basic?

J

JimmyB

I am getting a PivtTable Property error when I try to update a pivot table
using visual basic. The error occurs when the code attempts to select the
Page name in the pivot table and then change it to the next name. All of the
names are listed on an Excel worksheet in the same Excel file. The lines of
code that I'm using to switch the name are as follows:

Sheets("Pvt2").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields("Research
Associate"). _
CurrentPage = Sheets("Input Options").Range("o9").Value
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh

The third line of code contains the sheet and range reference where the page
name is found. On the Excel worksheet, the names are listed as John Doe with
no quotation marks surrounding them. The code always looks at the same cell
location because that cell contains a vlookup that's based on a counter in
the code to change the name one time during each loop.

I think there's probably some type of setting that I'm missing before
updating the pivot table but I have no idea what it could be.

Any ideas on a fix?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top