Pivot Table field name is not valid

hgufrin

Board Regular
Joined
Apr 19, 2004
Messages
177
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I had this Exact formula running well when I first entered it. But now that I have saved it and reopened it, it does not work. It errors out.

Everyday I download a lot of information out of AS400. Then I run create a pivot table. It seems simple but I can not get this to work now.

Can you help? Incidentally, the "PivotTable13" below will change to PivotTable14 next time I try to run. Then it will be PivotTable15 and so on. Is this part of problem? Thanks for your help.

'Select the range
Sheets("Sheet1").Select
maxrows = Sheets("Sheet1").UsedRange.Rows.Count
maxcolumns = Sheets("Sheet1").UsedRange.Columns.Count
Sheets("Sheet1").Range(Cells(1, 1), Cells(maxrows, maxcolumns)).Name = "Sheet1"

ActiveWindow.SmallScroll ToRight:=20
Range("Z1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1").CreatePivotTable TableDestination:= _
"[crap]Sheet1!R3C26", TableName:="PivotTable13", DefaultVersion:= _
xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable13").PivotFields("TRANS TYPE")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable13").AddDataField ActiveSheet.PivotTables( _
"PivotTable13").PivotFields("tons"), "Sum of tons", xlSum
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,519
Messages
6,125,294
Members
449,218
Latest member
Excel Master

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