VB change filter based on cell value error: run-time error '1004' unable to set the currentpage property of the pivotfield class.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
758
Hello friends, hope all is well.

I am trying to have a code that goes to a cell, picks up the date, and applies it to the filtered field of the pivot/power pivot.

I am getting an error (run-time error '1004' unable to set the currentpage property of the pivotfield class).

after debugging I get the following highlighted:
Code:
.CurrentPage = "All"

Please help me make the code run without errors.

Thanks a lot in advance!


Code:
Sub FilterMonth()

Dim pt As PivotTable
Dim Field As PivotField
Dim Stng As String

'defining the pivot table and the field
Set pt = Worksheets("Pivot").PivotTables("PivotTable1")
Set Field = pt.PivotFields("[dr salary database].[month].[month]")

'the date value
Stng = Worksheets("summary").Range("m4").Value

With Field
.ClearAllFilters
'this line below doesn't work
.CurrentPage = "All"
pt.RefreshTable
End With

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I would use CurrentPageName and see if that works, in place of CurrentPage. I was having a similar issue with it.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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