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 chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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?
 

wish2excel

New Member
Joined
Aug 19, 2010
Messages
20
the second line causes the error, the variables my name is for the agent name and dselect is for the date.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

wish2excel

New Member
Joined
Aug 19, 2010
Messages
20

ADVERTISEMENT

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.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Date").CurrentPage = CStr(dselect)
 

wish2excel

New Member
Joined
Aug 19, 2010
Messages
20
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,342
Messages
5,641,592
Members
417,224
Latest member
llama9207

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
Top