Run-time error '1004': The Pivot Table field name is not valid

shawnrpg

New Member
Joined
Oct 23, 2009
Messages
31
Hi all,

I have a rather lengthy macro that concules by refreshing two different pivot tables. This macro has been in use for several months now with no issues but yesterday the user called me and stated that she was getting an error.
The error is "Run-time error '1004': The Pivot Table field name is not valid. To create a Pivot Table report, you must use data that is organized as a list with labeled columns. If you are changing the name of the Pivot Table field, you must type a new name for the field."

The potion of the code where the error occurs is on the "PivotCache.Refresh" line of the following:
Sheets("Quote_RFQ_Received").Select
ActiveSheet.PivotTables("PivotTable3").PivotSelect "", xlDataAndLabel, True
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
Range("B4").Select

It appears that the code doesn't like the name "PivotTable3" -- although it didn't have a problem with it before yesterday.

I found a similar thread to this on this message board but the responses were to ensure that the PT name in the code matched what is actually on the PT in the spreadsheet. I followed the different examples to determine the actual table name and I can confirm that the name in the code matches PT field name.
I also confirmed that each of the three PT columns had headers.

I tried the macro on a couple other machines (besides the daily user) and the same error occurs. Now here's the really odd thing; when I run the macro on my machine, it works fine.

Any ideas on 1) why it has worked for the past couple months and all of a sudden an error occurs, 2) why the macro works fine on my machine but not others, and most importantly 3) what is the fix.

Thanks for your help,

Shawn
 
guys, I have same problem
the VBA code below works before, last week ok, but today not working and the named message was shown
the problem is highlighted
please help me, i spent so much time working on this
original code from book Pivot Table Data Crunching<o:p></o:p>

Sub Branch_Amount()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
' Page 206 of Pivot Table Data Crunching<o:p></o:p>
Dim WSD As Worksheet<o:p></o:p>
Dim PTCache As PivotCache<o:p></o:p>
Dim pt As PivotTable<o:p></o:p>
Dim PRange As Range<o:p></o:p>
Dim FinalRow As Long<o:p></o:p>
Set WSD = Worksheets("PivotTable")<o:p></o:p>
<o:p></o:p>
Application.ScreenUpdating = False<o:p></o:p>
<o:p> </o:p>
Application.DisplayAlerts = False<o:p></o:p>
<o:p> </o:p>
<o:p></o:p>
<o:p></o:p>
' Delete any prior pivot tables<o:p></o:p>
For Each pt In WSD.PivotTables<o:p></o:p>
pt.TableRange2.Clear<o:p></o:p>
Next pt<o:p></o:p>
WSD.Range("DA1:KH1").EntireColumn.Clear<o:p></o:p>
<o:p></o:p>
' Define input area and set up a Pivot Cache<o:p></o:p>
FinalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row<o:p></o:p>
FinalCol = WSD.Cells(1, Application.Columns.Count). _<o:p></o:p>
End(xlToLeft).Column<o:p></o:p>
Set PRange = WSD.Cells(1, 1).Resize(FinalRow, FinalCol)<o:p></o:p>
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:= _<o:p></o:p>
xlDatabase, SourceData:=PRange.Address)<o:p></o:p>
<o:p></o:p>
' Create the Pivot Table from the Pivot Cache<o:p></o:p>
Set pt = PTCache.CreatePivotTable(TableDestination:=Worksheets("Branch_Amount"). _<o:p></o:p>
Cells(2, 2), TableName:="PivotTable1")<o:p></o:p>
<o:p></o:p>
' Turn off updating while building the table<o:p></o:p>
pt.ManualUpdate = False<o:p></o:p>
<o:p></o:p>
' Set up the row & column fields<o:p></o:p>
pt.AddFields RowFields:=Array("AGENCIJA_NAZIV"), _<o:p></o:p>
ColumnFields:="Data"<o:p></o:p>
<o:p> </o:p>
' Set up the data fields<o:p></o:p>
With pt.PivotFields("SALDO")<o:p></o:p>
.Orientation = xlDataField<o:p></o:p>
.Function = xlSum<o:p></o:p>
.Position = 1<o:p></o:p>
.NumberFormat = "#,###"<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>
With pt.PivotFields("KATEGORIJA")<o:p></o:p>
.PivotItems("A").Visible = True<o:p></o:p>
.PivotItems("B").Visible = True<o:p></o:p>
.PivotItems("C").Visible = True<o:p></o:p>
.PivotItems("D").Visible = True<o:p></o:p>
<o:p></o:p>
End With<o:p></o:p>
<o:p> </o:p>
With pt.PivotFields("TIP_KOMITENTA")<o:p></o:p>
.PivotItems("B").Visible = True<o:p></o:p>
.PivotItems("C").Visible = True<o:p></o:p>
.PivotItems("R").Visible = True<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>
With pt.PivotFields("FILIJALA_NAZIV")<o:p></o:p>
.Subtotals(1) = False<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>
' Calc the pivot table<o:p></o:p>
pt.ManualUpdate = False<o:p></o:p>
pt.ManualUpdate = False<o:p></o:p>
<o:p></o:p>
' Format the pivot table<o:p></o:p>
pt.ShowTableStyleRowStripes = True<o:p></o:p>
pt.TableStyle2 = "PivotStyleMedium10"<o:p></o:p>
<o:p></o:p>
Worksheets("Branch_Amount").Range("B:H").EntireColumn.AutoFit<o:p></o:p>
<o:p> </o:p>
End Sub
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
i did adequate grouping, like it is the same row heading as last week, it did not changed at all.
i think the main problem is with pivot cache.
i do not know how it can work last week, this week not working:(
 
Upvote 0
Please post a list of your headings. The error indicates that one or more of your headings is invalid. If you select A1 and press End+RightArrow does it take you to the last column in your headings? If you press End+RightArrow again does it take you to IV1? If not you have a blank cell in your header row.
 
Upvote 0
dear andrew, i know what is needed to make pivot table report - to not have any blank cells in the column header, and i do not have any blanks

i do not know how but now the code is working. i was searching entire web and looking for solution, and i was looking my file from last week and this week.
it seems that the problem was that in the last week file i did not have any links to other columns, which i had this week.
after i made copy / paste as values i got code working great, like last week
i guess i was so lucky to figure out what was happening.
i hope next week i would not have any problems with this code.

thx andrew for helping me, for this week it is working ok
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,207
Members
449,214
Latest member
mr_ordinaryboy

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