VBA Pivot Table Run-time Error '1004'

mesmanc

New Member
Joined
Apr 28, 2014
Messages
4
Greetings,

I am currently experiencing the following error: Run-time error '1004': Unable to get the PivotFields property of the PivotTable class on this line of code: With ActiveSheet.PivotTables("PivotTable2").PivotFields("Count of Project")

I can change "Count of Project" to "Project" and i get a different error: Run-time error '1004': Unable to set the Position property of the PivotField class with .Position = 2 highlighted.

I am trying to run 3 different pivot tables within 1 new sheet. The first table populates without any issue, but the second table only populates the first "Projects" column and not the "Count of Projects"

Thanks for the help!

Code:
    Rows("1:3").Select    Selection.Delete Shift:=xlUp
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    DataSheet = ActiveSheet.Name
    Sheets.Add
    NewSheet = ActiveSheet.Name
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        DataSheet & "!R1C1:R" & FinalRow & "C14", Version:=xlPivotTableVersion14). _
        CreatePivotTable TableDestination:=NewSheet & "!R3C1", TableName:="PivotTable1" _
        , DefaultVersion:=xlPivotTableVersion14
    Sheets(NewSheet).Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Assignee")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Key")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Key"), "Count of Key", xlCount
    ActiveCell.Offset(0, 3).Range("A1").Select
    Sheets(NewSheet).Select
   ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        DataSheet & "!R1C1:R" & FinalRow & "C14", Version:=xlPivotTableVersion14). _
        CreatePivotTable TableDestination:=NewSheet & "!R3C4", TableName:="PivotTable2" _
        , DefaultVersion:=xlPivotTableVersion14
    Sheets(NewSheet).Select
    Cells(3, 4).Select
     With ActiveSheet.PivotTables("PivotTable2").PivotFields("Project")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Count of Project")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable2").PivotFields("Project"), "Count of Project", xlCount
    ActiveCell.Offset(0, 5).Range("A1").Select
    Sheets(NewSheet).Select
    ActiveWorkbook.Worksheets(NewSheet).PivotTables("PivotTable2").PivotCache. _
        CreatePivotTable TableDestination:=NewSheet & "!R3C7", TableName:="PivotTable3" _
        , DefaultVersion:=xlPivotTableVersion14
    Sheets(NewSheet).Select
    Cells(3, 7).Select
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Priority")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("Key")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Key"), "Count of Key", xlCount
    ActiveWindow.SmallScroll Down:=-12
    ActiveCell.Offset(-1, -6).Range("A1").Select
    ActiveCell.FormulaR1C1 = "Overdue JIRAs By Employee"
    ActiveCell.Offset(0, 3).Range("A1").Select
    ActiveCell.FormulaR1C1 = "Overdue JIRAs by Client"
    ActiveCell.Offset(0, 3).Range("A1").Select
    ActiveCell.FormulaR1C1 = "Overdue JIRAs by Priority"
    ActiveCell.Offset(0, -6).Range("A1").Select
    Selection.Font.Bold = True
    ActiveCell.Offset(0, 3).Range("A1").Select
    Selection.Font.Bold = True
    ActiveCell.Offset(0, 3).Range("A1").Select
    Selection.Font.Bold = True
    ActiveCell.Offset(9, 5).Range("A1").Select
    ActiveWindow.SmallScroll Down:=-36
    ActiveCell.Offset(-9, -11).Range("A1").Select
    Selection.Font.Size = 12
    ActiveCell.Offset(0, 3).Range("A1").Select
    Selection.Font.Size = 12
    ActiveCell.Offset(0, 3).Range("A1").Select
    Selection.Font.Size = 12
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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