Pivot table refresh

G

Guest

Private Sub Worksheet_Change(ByVal Target As Range)

ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh

End Sub

I am using the above macro to refresh two pivot tables on the same
worksheet. the problem is when I change a value on the worksheet and the
macro runs, it seems to run as an endless loop. Please help.
 
D

Dave Peterson

Private Sub Worksheet_Change(ByVal Target As Range)

application.enableevents = false
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
application.enableevents = true

End Sub

This tells excel to stop looking for changes, then do the refreshing, then start
looking for changes again.
 
G

Guest

Thanks Dave.

I did not seem to have this problem when the pivot tables were on different
worksheets. Do you still recommend I use application.enableevents = false.
 
D

Dave Peterson

If you have a worksheet_change event in the worksheet with that other
pivottable, you may want to use it.
 
G

Guest

Thanks again Dave.

Does this mean if I have a worksheet_change event in the worksheet but the
pivottable I am refreshing is another worksheet, I do not need to use
application.enableevents.
 
D

Dave Peterson

It could.

I didn't test it, but did it start going into one of those giant loops without
those statements?
Thanks again Dave.

Does this mean if I have a worksheet_change event in the worksheet but the
pivottable I am refreshing is another worksheet, I do not need to use
application.enableevents.
 

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