Hi,
I had a report with some vba attached to it that switched the pivot tables between showing number of passengers and total revenue at the press of a macro button.
I have changed the pivots to data model pivots and now my vba script doesnt work.
Is there anything i need to do differently?
link to 5mb file: https://drive.google.com/open?id=1ipEGhcZIiscWWy6HzWWdAomt7nATDQDA
Thanks
Chris
I had a report with some vba attached to it that switched the pivot tables between showing number of passengers and total revenue at the press of a macro button.
I have changed the pivots to data model pivots and now my vba script doesnt work.
Is there anything i need to do differently?
link to 5mb file: https://drive.google.com/open?id=1ipEGhcZIiscWWy6HzWWdAomt7nATDQDA
Thanks
Chris
Code:
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = ThisWorkbook.Sheets("Top Pax Summary").Range("AO3")
Dim pt1, pt2, pt3, pt4 As PivotTable
Dim Field1 As PivotField
Dim pi As PivotItem
Dim sumField As String
sumField = Range("AO5").Value
'-----Pivot1-----
Set pt1 = PivotTables("PivotTable1")
pt1.DataFields(1).Orientation = xlHidden
pt1.PivotFields(sumField).Orientation = xlDataField
pt1.AllowMultipleFilters = True
pt1.RefreshTable
If sumField = "Total Revenue" Then
ActiveSheet.PivotTables("PivotTable1").PivotFields("Main Tour Code").AutoSort _
xlDescending, "Sum of Total Revenue", ActiveSheet.PivotTables("PivotTable1"). _
PivotColumnAxis.PivotLines(1), 1
Else
ActiveSheet.PivotTables("PivotTable1").PivotFields("Main Tour Code").AutoSort _
xlDescending, "Sum of Pax", ActiveSheet.PivotTables("PivotTable1"). _
PivotColumnAxis.PivotLines(1), 1
End If
'-----Pivot2-----
Set pt2 = PivotTables("PivotTable2")
pt2.DataFields(1).Orientation = xlHidden
pt2.PivotFields(sumField).Orientation = xlDataField
pt2.AllowMultipleFilters = True
pt2.RefreshTable
'-----Pivot3-----
Set pt3 = PivotTables("PivotTable3")
pt3.DataFields(1).Orientation = xlHidden
pt3.PivotFields(sumField).Orientation = xlDataField
pt3.AllowMultipleFilters = True
pt3.RefreshTable
'-----Pivot4-----
Set pt4 = PivotTables("PivotTable4")
pt4.DataFields(1).Orientation = xlHidden
pt4.PivotFields(sumField).Orientation = xlDataField
pt4.AllowMultipleFilters = True
pt4.RefreshTable
End Sub