• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Normal Pivot vs Data Model Pivot

Christof

Member
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


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
 
Back
Top