PivotTables/VBA

  • Thread starter Thread starter jngi
  • Start date Start date
J

jngi

Any VBA/Pivot table experts out there?


I have two identical workbooks, one old, one new. The
only difference between them is the data. In the old one
I can set up a pivot table using code - the new one gives
the error with exactly the same code:

'Unable to get the PivotFields property of the
PivotTable class'

The error occurs in the first row of the following code:

With ActiveSheet.PivotTables("PivotTable2").PivotFields
("Mode")
.Orientation = xlRowField
.Position = 1
End With

I can set up the pivot table in the new sheet manually
every time but when I try it with code it fails.

Help!
 
It seems like your code is pointing to a range ("PivotTable2") that
doesn't exist in your new workbook.

The PivotTable names are automatically generated by Excel,
PivotTable1, PivotTable2, PivotTable3, etc. If this is the first
PivotTable in the new workbook, it's name might be PivotTable1,
therefore asking to pull a field in from PivotTable2 would be
impossible.

Check the name of the table, by right-clicking anywhere inside it and
viewing the "table options." If it's not named PivotTable2, then
replace your code with the new name and try to run it.

Hope that helps solve your issue...
 
Thanks Jacinta

I forgot to mention that I have tried all sorts of
different names in the line to no avail.

Is there a way of using an index like (2) instead of a
name in quotes?

Thanks again

Jon
 

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

Back
Top