Pivot Table field name is not valid

hgufrin

Board Regular
Joined
Apr 19, 2004
Messages
172
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,137,337
Messages
5,680,904
Members
419,939
Latest member
AJWildOne

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
Top