Attaching macro to a pivot table drop down

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Hi - I'm wondering if I can attach a macro to one of the
drop down fields in my pivot table. IE - when I
choose "Yes" from one of my drop down fields in my pivot
table, I want to attach a macro to this action...any help
is appreciated!
 
To run a macro when the page field is changed, use code similar to the
following, where the page field is named "Region" --

'========================================
Dim mvPivotPageValue As Variant

Private Sub Worksheet_Calculate()
'variation on code by Robert Rosenberg 2000/01/11
''I use a module level variable (see above) to keep track of
''the last selection from the Page Field.
''This routine was place in the Worksheet
''containing the PivotTable's code module.
Dim pvt As PivotTable

Set pvt = ActiveSheet.PivotTables(1)
If LCase(pvt.PivotFields("Region").CurrentPage) _
<> LCase(mvPivotPageValue) Then
Application.EnableEvents = False
mvPivotPageValue = _
pvt.PivotFields("Region").CurrentPage
'your macro name here
Application.EnableEvents = True
End If
End Sub
'==============================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top