Hi,
I've created a pivot table and can use some code to select the table range, row range and databodyrange. This works. However when I try to narrow the selection down to a specific Customer Number the error "Run-time error '1004': Unable to get the PivotFields property of the PivotTable class" occurs. I understand this is effectively saying there is no pivot field called "Customer Number" however this is how the pivot field source data is named and is the name showing in the pivot table. I've included a screen shot & code used below.
The code I'm using is:
Sub Lease()
Dim pt As PivotTable
Set pt = Sheets("pivots").PivotTables("Lease")
pt.TableRange1.Select ' this works
pt.DataBodyRange.Select ' this works
pt.RowRange.Select 'this works
End Sub
Sub test()
Dim pt As PivotTable
Set pt = Sheets("pivots").PivotTables("Lease")
'
pt.DataLabelRange.Select ' this errors
pt.PivotFields("Customer Number").PivotItems("11839.01").DataRange.Select ' this errors
End Sub
Any ideas as to why this won't work?
thanks in advance for any answers
I've created a pivot table and can use some code to select the table range, row range and databodyrange. This works. However when I try to narrow the selection down to a specific Customer Number the error "Run-time error '1004': Unable to get the PivotFields property of the PivotTable class" occurs. I understand this is effectively saying there is no pivot field called "Customer Number" however this is how the pivot field source data is named and is the name showing in the pivot table. I've included a screen shot & code used below.
The code I'm using is:
Sub Lease()
Dim pt As PivotTable
Set pt = Sheets("pivots").PivotTables("Lease")
pt.TableRange1.Select ' this works
pt.DataBodyRange.Select ' this works
pt.RowRange.Select 'this works
End Sub
Sub test()
Dim pt As PivotTable
Set pt = Sheets("pivots").PivotTables("Lease")
'
pt.DataLabelRange.Select ' this errors
pt.PivotFields("Customer Number").PivotItems("11839.01").DataRange.Select ' this errors
End Sub
Any ideas as to why this won't work?
thanks in advance for any answers