nparsons75
Well-known Member
- Joined
- Sep 23, 2013
- Messages
- 1,256
- Office Version
- 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
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
_