Automating a Ctrl+ Recorded macro

ryanduck

New Member
Joined
Apr 13, 2011
Messages
37
I'm using a ctrl+r (r in this case) recorded macro to refresh a auto-filter every time I filter a pivot table using page fields.

Ideally instead of hitting ctrl+r to start the recorded macro, I would like to have it happen automatically every time I filter the pivot table using the page fields...

Any ideas?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi

This is possible I think - I did not test it.

Try to use the

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

End Sub

event in the correct sheet. You can add the code if you right-click that worksheet, and paste the code above in the white canvas. Then between the 2 lines of codes, add the name of the procedure to be executed.

Can you try it and give feedback please?

Wigi
 
Upvote 0
This did not work:

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Selection.AutoFilter Field:=1, Criteria1:=">0", Operator:=xlOr, _
        Criteria2:="=*"
End Sub

Hi

This is possible I think - I did not test it.

Try to use the

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 
End Sub

event in the correct sheet. You can add the code if you right-click that worksheet, and paste the code above in the white canvas. Then between the 2 lines of codes, add the name of the procedure to be executed.

Can you try it and give feedback please?

Wigi
 
Upvote 0
i KNOW that this works (it does for me)


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim iSect As Range
    Set iSect = Application.Intersect(Target, Range("b4"))
    If Not iSect Is Nothing Then
        Call PivotMacro
    End If
End Sub

it workes because i have a target range set to B4 which is the filter that i always use on my pivot, however im pretty sure you can set a range of cells to be the target.

HTH
 
Upvote 0
Hi,

Following wigi's suggestion, try this

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
    Call MyMacro
End Sub

Use the name of your macro instead of MyMacro.
(maybe in your macro you have to specify the range to be filtered instead of Selection)

HTH

M.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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