Creating a button to select from a Pivot table filter

chriswhincup

New Member
Joined
Apr 19, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have a filter for a pivot table and the list is essentially 2000 sales people. I only ever need to be able to select one of 6 names. I don't want to use a slicer as that shows all 2000 names and scrolling makes it difficult. The filter then brings up a slicer with the stores that person looks after. Selecting the store then updates the data from 9 other linked pivot tables into a dashboard.

I thought I could use a button and assign a recorded macro to it that just chooses the name from the filter but its not working properly. It works fine when its recording and does exactly what its meant to do. Can anyone spot anything glaringly obvious with the code? The debug seems to highlight the line with CurrentPage and the line below on it. Alternatively if there is a better way to do it?

Sub HelenRouse()
'
' HelenRouse Macro
'

'
ActiveSheet.PivotTables("PivotTable8").PivotFields( _
"[Sales Person].[Sales Person].[Sales Person]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable8").PivotFields( _
"[Sales Person].[Sales Person].[Sales Person]").CurrentPage = _
"[Sales Person].[Sales Person].&[HELEN ROUSE]"
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Don't know much about pivot tables but do know a thing or two about concatenation in code. You are including the ampersand as a literal character in the reference and I doubt that anything is named "&[HELEN ROUSE]". Try "[Sales Person].[Sales Person]." & "[HELEN ROUSE]"
If the first line in your code doesn't raise an error then I guess including brackets ( [ ) in your references is OK, but as I noted, pivot stuff isn't my thing. It may also be that there will be a missing double quote or two as a result of breaking it up like that.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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