I have been trying to automate a pivot table using various methods, yet each one has given me an error. This has been mostly due to the fact that I am trying to create a variable range and pivot tables may already exist in the spreadsheet I am using.
This most recent method worked on a test spreadsheet, however it did not work on the actual spreadsheet that I would like to use it on. The spreadsheet already has a pivot table, which may be the issue? The code is stopped at set objTable =Sheet1.PivotTable
Dim objTable As PivotTable
Dim objField As PivotField
ActiveWorkbook.Sheets("Roster").Select
Range("A1").Select
Set objTable = Sheet1.PivotTableWizard
Set objField = objTable.PivotFields("Member Type")
objField.Orientation = xlRowField
Set objField = objTable.PivotFields("AIA Member Status")
objField.Orientation = xlColumnField
Set objField = objTable.PivotFields("Customer")
objField.Orientation = xlDataField
objField.Function = xlCount
Set objField = objTable.PivotFields("Expire Date")
objField.Orientation = xlPageField
objTable.PivotFields("Expire Date"). _
CurrentPage = expireyear
objTable.PivotFields("Member Type") _
.PivotItems("Cornerstone Partners").Visible = False
objTable.PivotFields("Member Type") _
.PivotItems("Honorary AIA").Visible = False
objTable.PivotFields("Member Type") _
.PivotItems("Honorary Fellow").Visible = False
objTable.PivotFields("AIA Member Status") _
.PivotItems("Proforma").Visible = False
Range("A6, A8").Select
Range("A8").Activate
Selection.Group
Range("A6").Select
objTable.PivotFields("Member Type2").PivotItems( _
"Group1").Caption = "Architect"
objTable.PivotFields("Member Type2").PivotItems( _
"Architect").ShowDetail = False
Range("A7,A8,A10").Select
Range("A7").Activate
Selection.Group
Range("A7").Select
objTable.PivotFields("Member Type2").PivotItems( _
"Group2").Caption = "Emeritus"
objTable.PivotFields("Member Type2").PivotItems( _
"Emeritus").ShowDetail = False
objTable.PivotFields("Member Type2").PivotItems( _
"Associate").ShowDetail = False
objTable.PivotFields("Member Type2").PivotItems( _
"International Associate").ShowDetail = False
objTable.PivotFields("Member Type2").PivotItems( _
"International Associate").ShowDetail = False
objTable.PivotFields("Member Type2").PivotItems( _
"Allied").ShowDetail = False
objTable.PivotFields("Member Type2").PivotItems( _
"Allied").Position = 5
objTable.PivotFields("Member Type2").PivotItems( _
"Emeritus").Position = 4
Thank you in advance