VBA PivotTable RowField CurrentPage Filter and PageField CurrentPage Filter

Stein

New Member
Joined
Aug 13, 2014
Messages
3
I have two PivotFields. One will be a PageField while the other is a RowField. My macro will switch them, while also grabbing values from the top of the page and using these values as the CurrentPage for each Field. I get an error when running the macro that says Error 1004: Unable to Get the CurrentPage Property of the PivotField Class. It can set the PageField Class CurrentPage, but not the RowField. Here is my code (look for my comments)...
Code:
Sub EWOCountPillar_RC()
Dim sh As Worksheet
Dim pt As PivotTable
Set sh = Sheets("EWO Count Table")
Set pt = sh.PivotTables("pt3")
If Application.ScreenUpdating = True Then Application.ScreenUpdating = False
If pt.ManualUpdate = False Then pt.ManualUpdate = True
Dim pf1 As PivotField, pf2 As PivotField
Set pf1 = pt.PivotFields("WCM_Pillar")
Set pf2 = pt.PivotFields("Root_Cause")
    If pf1.Orientation = xlColumnField Then
        pf1.Orientation = xlHidden
        pf2.Orientation = xlColumnField
    Else
        pf2.Orientation = xlHidden
        pf1.Orientation = xlColumnField
    End If
    
If Application.ScreenUpdating = False Then Application.ScreenUpdating = True
If pt.ManualUpdate = True Then pt.ManualUpdate = False
End Sub
Sub EWOCountPA_Mach()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim pt As PivotTable
Set sh1 = Sheets("EWO Count Table")
Set pt = sh1.PivotTables("pt3")
If Application.ScreenUpdating = True Then Application.ScreenUpdating = False
If pt.ManualUpdate = False Then pt.ManualUpdate = True
Dim r1 As Range, r2 As Range
Dim str1 As String, str2 As String
Dim pf1 As PivotField, pf2 As PivotField
Set sh2 = Sheets("EWO Count")
Set r1 = sh2.Range("F1")
Set r2 = sh2.Range("H1")
str1 = r1.Value
str2 = r2.Value
Set pf1 = pt.PivotFields("Process_Area")
Set pf2 = pt.PivotFields("Machine")

    If pf1.Orientation = xlRowField Then
        pf1.ClearAllFilters
        pf1.Orientation = xlPageField
        pf2.Orientation = xlRowField
        pf2.AutoSort xlDescending, "Count of EWO"
        str1 = r1.Value
        
            If r2.Value = "(All)" Then
                str2 = "(Select All)"
            Else
                str2 = r2.Value
            End If
            
        pf1.CurrentPage = str1
        pf2.ClearAllFilters
        pf2.CurrentPage = str2                                      'Here is the Error
    Else
        pf2.ClearAllFilters
        pf1.Orientation = xlRowField
        pf2.Orientation = xlPageField
        pf1.AutoSort xlDescending, "Count of EWO"
        str2 = r2.Value
        
            If r1.Value = "(All)" Then
                str1 = "(Select All)"
            Else
                str1 = r1.Value
            End If
        
        pf2.CurrentPage = str2
        pf1.ClearAllFilters
        pf1.CurrentPage = str1                                       'Here is the Error
    End If
    
If Application.ScreenUpdating = False Then Application.ScreenUpdating = True
If pt.ManualUpdate = True Then pt.ManualUpdate = False
End Sub
Thanks if you can help me out! I can't continue my project until I figure this out.
 

Forum statistics

Threads
1,082,015
Messages
5,362,690
Members
400,686
Latest member
Teeks91

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top