VBA Code Error

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,256
Office Version
  1. 2016
Hi,

I have a macro running which includes this information below. When the macro runs I get this error:

Run time error '1004'
The pivot table field name is not valid. To create a pivot table report, you must use data that is organised 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.

Would anyone have any ideas why?

Thanks in advance...


Code included within macro, full macro below.

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"FILTER_DATA!R1C1:R1048576C4", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="PIVOTS!R4C169", TableName:= _
"PivotTable41", DefaultVersion:=xlPivotTableVersion12


Code:
Sub Filter_CopyPasteFilter()
Application.ScreenUpdating = False


    Sheets("FILTER_DATA").Select
    Cells.Select
    Selection.Clear
    
    Sheets("PIVOTS").Select
    Columns("Fm:fp").Select
    Selection.Clear


Sheets("DATA").Select
ActiveSheet.AutoFilter.Range.Copy
Sheets("FILTER_DATA").Select
Sheets("FILTER_DATA").Paste


Sheets("FILTER_DATA").Select
Rows("1:1").Select
Selection.ClearFormats
    
Call DeleteBlankRows
Call PIVOT_Final


End Sub


Sub DeleteBlankRows()
Sheets("FILTER_DATA").Select
 
Range("BQ2:BT5000").Select
Selection.Cut
Range("BM5001").Select
ActiveSheet.Paste


Range("BU2:BX5000").Select
Selection.Cut
Range("BM10001").Select
ActiveSheet.Paste


Range("BY2:CB5000").Select
Selection.Cut
Range("BM15001").Select
ActiveSheet.Paste


Range("CC2:CF5000").Select
Selection.Cut
Range("BM20001").Select
ActiveSheet.Paste


Columns("A:BL").Select
Range("BL1").Activate
Selection.Delete Shift:=xlToLeft
Columns("E:U").Select
Selection.Delete Shift:=xlToLeft
Range("A:D").Select




On Error Resume Next


Selection.EntireRow.SpecialCells(xlBlanks).EntireRow.Delete


On Error GoTo 0


End Sub


Sub PIVOT_Final()


    Sheets("PIVOTS").Select
    Range("FM4").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "FILTER_DATA!R1C1:R1048576C4", Version:=xlPivotTableVersion12). _
        CreatePivotTable TableDestination:="PIVOTS!R4C169", TableName:= _
        "PivotTable41", DefaultVersion:=xlPivotTableVersion12
    Sheets("PIVOTS").Select
    Cells(4, 169).Select
    With ActiveSheet.PivotTables("PivotTable41").PivotFields("PART No")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable41").AddDataField ActiveSheet.PivotTables( _
        "PivotTable41").PivotFields("GOOD"), "Count of GOOD", xlCount
    ActiveSheet.PivotTables("PivotTable41").AddDataField ActiveSheet.PivotTables( _
        "PivotTable41").PivotFields("DEFECT"), "Count of DEFECT", xlCount
    ActiveSheet.PivotTables("PivotTable41").AddDataField ActiveSheet.PivotTables( _
        "PivotTable41").PivotFields("SCRAP"), "Count of SCRAP", xlCount
    With ActiveSheet.PivotTables("PivotTable41").PivotFields("Count of GOOD")
        .Caption = "Sum of GOOD"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable41").PivotFields("Count of DEFECT")
        .Caption = "Sum of DEFECT"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable41").PivotFields("Count of SCRAP")
        .Caption = "Sum of SCRAP"
        .Function = xlSum
    End With
    
    Sheets("PIVOTS").Select
    Range("FM1").Select
End Sub
 _
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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