Adding button to worksheet to refresh pivot table data

R

Ron

I've created a daily input worksheet and it kicks out the results to a pivot
table. I want to create a button on that chart for the user to click on so
it can refresh data. Doing so just in case they don't have the pivot table
menu open, or forget to click in chart to bring up the refresh data button
 
R

Roger Govier

Hi Ron

Add the following code to the button on your sheet

Sub Refresh_Pivot()
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
End Sub

Change the name of the Pivot Table to the correct one for you.
To find the name, right click on your PT>Table Options> name will be shown
at top of dialogue.

Alternatively, rather than attaching code to a button, you could use a
worksheet event to cause the PT to be refreshed as soon as the tab is
selected.

Private Sub Worksheet_Activate()
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh

End Sub

The above code needs to be copied, then right click on the sheet tab with
the PT>View code>Paste code into the white pane.
 

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

Top