PivotTableUpdate continous loop

Eckerslike

New Member
Joined
Jul 4, 2008
Messages
2
Hi,

I have a pivot table that has data for a few years with the columns being the years, what I want to do is sort the data by the column that has 2008 in it, if you use the automatic sort is sums all the years together and effectively sorts by the Grand Total and not the latest year.

I have created a Macro that sorts the data as I would like it and I have assigned that to a button and it works fine.

What I am trying to do is use the Worksheet_PivotTableUpdate to run that macro so that the user does not have to click the button everytime they select something different.

The problem that I have is that when the macro runs it updates the pivot table, so it then creates a continous loop.

Does anyone know a way round this issue, so that it only runs once each time the user changes the selection criteria.

Thanks in advance.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
why not put your macro in the PT Update event -- in which case in theory you shouldn't need to update it in your own code (as it's been updated already)
 
Upvote 0
I have found the solution.

Application.EnableEvents = False
' appropriate action here
Application.EnableEvents = True


This stops it from calling the event again during the running of the macro.
 
Upvote 0

Forum statistics

Threads
1,214,383
Messages
6,119,196
Members
448,874
Latest member
Lancelots

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