Pivot table creation error 1004: Pivottable field name is not valid

vinu315

New Member
Joined
Jul 22, 2014
Messages
2
Hi all,

I am having a peculiar error with excel VBA today. In the code below, are two ways I am using to create a Pivot table. Option 1 is creating the pivot table in the same sheet that the data is in. Option 2 is creating the pivot table in a new sheet. Option 2 does not work. As you can see both codes refer to the exact same data set. All header columns are populated. Not sure where the error is coming from other than the location of the pivot table could be throwing a bug?

The error is as follows:
Run-time error '1004': The [ivottable field name is not valid. To create a Pivottable report, you m ust use data that is organized as a list with labeled columns. If you are changing the name of a pivottable field, you must type a new name for the field.

I am using Excel 2010

Please help.

Code:
With ThisWorkbook
    Set wkSheet = .Worksheets.Add
   
    'This code works fine (Option 1)
    '.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "RM data!R1C1:R3C3", Version:=xlPivotTableVersion14).CreatePivotTable _
    TableDestination:=Sheet1.Cells(1, 10), TableName:="PT3", DefaultVersion _
    :=xlPivotTableVersion14

    'This code results in an error (Option 2)
    .PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "RM data!R1C1:R3C3", Version:=xlPivotTableVersion14).CreatePivotTable _
    TableDestination:=wkSheet.Cells(3, 1), TableName:="PT3", DefaultVersion _
    :=xlPivotTableVersion14
End With
 

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,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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