unable to set the current.page priority of the pivot field class

alfani

New Member
Joined
Nov 12, 2010
Messages
5
Hello Excel/VBA Gurus,

Here is what caused me a headache in the past few days :)

I have a pivot table with a lot of data in it and I have very hard time to review it for unexpected deviations. The pivot table sales of tomatos by client by date for the last three months.
I am trying to create a macro that will help me go through the sales for each Partner (by filtering per partner in the pivot table) and look at the pivot chart that is fead by the results of the pivot table. On every "ENTER" click I want to move to the next partner and see the Chart for the sales per day for the 3 months.

I started with a code that I found in internet (see below) but when I run it I get the error in the title of the post and I do not know why.

Your help would be very much appreciated!

the code:

Sub Apply_Filter()
Dim pvtTable As PivotTable
Dim pvtField As PivotField
Dim pvtItem As PivotItem
Dim filterClient As String

Set pvtTable = Worksheets("Sheet1").PivotTables("PivotTable2")
Set pvtField = pvtTable.PivotFields("Client Name")

filterClient = Worksheets("Sheet1").Range("c1").Value
' In "C1" I have one of the Clients just to see whether it will be picked up
' by the Pivot. Then I planned to make some loop through a list of partners ' for which I want to see the sales

For Each pvtItem In pvtField.PivotItems
If pvtItem.Value = filterClient Then
pvtField.CurrentPage = filterClient 'this is where I get the error
Exit For
End If
Next pvtItem

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Your code worked for me. Are you sure that Client name is a Page field?

Sorry for replying with such delay, I was on a training, obviously not on Excel/VBA :)

Thanks so much, Andrew!

Your question solved the issue, I simply did not have this field (Client Name) as field in the Report Filter area, it was placed instead in the Row Labels area

I will try to build the rest of the code myself and if someone is interested, will post the result.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,683
Members
452,937
Latest member
Bhg1984

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