unable to set the currentpage property pf the pivotfield class

wish2excel

New Member
Joined
Aug 19, 2010
Messages
20
Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Agent Name").CurrentPage = MyName
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Date").CurrentPage = dselect

Iam trying to update my pivot table with this code and i am getting an error "unable to set the currentpage property pf the pivotfield class"
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
What's in the variables MyName and dselect and which line causes the error? What would the code look like if strings were used instead of variables?
 
Upvote 0
the second line causes the error, the variables my name is for the agent name and dselect is for the date.
 
Upvote 0
If you record a macro while selecting a date from the page field what do you get? I think you will find that the date is a string.
 
Upvote 0
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/03/2011 by i81849
'
'
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Agent Name").CurrentPage = _
        "Karunakaran, Vipin"
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Date")
        .PivotItems("02/03/2011").Visible = False
        .PivotItems("03/03/2011").Visible = False
        .PivotItems("04/03/2011").Visible = False
        .PivotItems("07/03/2011").Visible = False
        .PivotItems("08/03/2011").Visible = False
        .PivotItems("(blank)").Visible = False
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Date")
        .PivotItems("01/03/2011").Visible = False
        .PivotItems("04/03/2011").Visible = True
    End With
End Sub
This is the recorded macro,but instead of selecting the value, I am trying to get the value from the user.
 
Upvote 0
I modified the code like this but still getting the same error.

Code:
Sub Macro1()
Dim dselect As String
dselect = Range("C1")

    ActiveSheet.PivotTables("PivotTable1").PivotFields("Agent Name").CurrentPage = _
        "Alex, George"
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Date").CurrentPage = CStr(dselect)
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top