Hi there,
I am trying to create a pivot table using excel data from another sheet, this is my code so far but when I run it, it has the following error message:
Run-Time Error '1004'
The pivot table field name is not valid. To create a pivottable report, you must use the data that is organised as a list with labelled columns. If you are changing the name of a pivot table field, you must type a new name for the field.
This is my code, I have highlight the bit that brings up the error:
Sub PivotTable()
Dim StrGLPivotTable As String
StrGLPivotTable = ("Pivot Table Analysis")
Dim WKSData As Worksheet
Set WKSData = ThisWorkbook.Worksheets("Trial Balance Comparison")
Dim RngData As Range
Set RngData = WKSData.UsedRange
Sheets.Add after:=ActiveSheet 'adding a new sheet
ActiveSheet.Name = StrGLPivotTable
Dim WKSDestination As Worksheet
Set WKSDestination = Sheets(StrGLPivotTable)
Dim PvtTable As PivotTable
Set PvtTable = WKSData.PivotTableWizard(SourceType:=xlDatabase, _
SourceData:=RngData, TableDestination:=ActiveSheet.Cells(1, 4))
Hope you can help.
Thank you
I am trying to create a pivot table using excel data from another sheet, this is my code so far but when I run it, it has the following error message:
Run-Time Error '1004'
The pivot table field name is not valid. To create a pivottable report, you must use the data that is organised as a list with labelled columns. If you are changing the name of a pivot table field, you must type a new name for the field.
This is my code, I have highlight the bit that brings up the error:
Sub PivotTable()
Dim StrGLPivotTable As String
StrGLPivotTable = ("Pivot Table Analysis")
Dim WKSData As Worksheet
Set WKSData = ThisWorkbook.Worksheets("Trial Balance Comparison")
Dim RngData As Range
Set RngData = WKSData.UsedRange
Sheets.Add after:=ActiveSheet 'adding a new sheet
ActiveSheet.Name = StrGLPivotTable
Dim WKSDestination As Worksheet
Set WKSDestination = Sheets(StrGLPivotTable)
Dim PvtTable As PivotTable
Set PvtTable = WKSData.PivotTableWizard(SourceType:=xlDatabase, _
SourceData:=RngData, TableDestination:=ActiveSheet.Cells(1, 4))
Hope you can help.
Thank you