Pivot Table Filter based on Selected Cell

dversloot1

Board Regular
Joined
Apr 3, 2013
Messages
113
Hello,

I have created a spreadsheet that identifies subcategories that go beyond x std deviations from the mean. I currently have it set up so that if a cell is selected, the table group name, category, subcategory are found using vba.

I would like to then take those values, and filter a pivot table on another sheet. The code stops on .ClearAllfilters

Sub IdentifySpike()

Dim col As Integer
Dim rw As Integer
Dim GrpNm, Cat, SubCat As Variant

rw = Selection.Row

GrpNm = Cells(rw, 1)
Cat = Cells(rw, 2)
SubCat = Cells(rw, 3)

If MsgBox("Are you sure you want to drill down into: " & vbNewLine & Cat & " --> " & SubCat & vbNewLine & "at " & GrpNm & "?", vbYesNo, "Identify Spikes") = vbYes Then

Sheets("DrilledDown").Select

Dim pt As PivotTable
Set pt = Sheets("DrilledDown").PivotTables("PivotTable1")

pt.PivotFields("Group Name").ClearAllFilters
pt.PivotFields("Group Name").CurrentPage = GrpNm

Else
Exit Sub
End If

End Sub

I would like to repeat this filter method for Cat and SubCat as well.

Any ideas?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
When I record a macro to perform the filter this is what I get:

ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Customer].[Group Name].[Group Name]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Customer].[Group Name].[Group Name]").CurrentPage = _
"[Customer].[Group Name].&[Amazon.Com CANADA]"

Does this help anyone for suggestions?
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,544
Members
449,169
Latest member
mm424

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