Preventing Recursion?

E

egun

I have two blocks of data on my worksheet: one with monthly dollar amounts,
and another with annual dollar amounts. I am using the Worksheet_Change
event to monitor any changes to either block of data. If the user enters a
monthly amount, then the annual sum is updated. If the user enters an amount
in the annual total cell, then that value is divided by 12 and placed into
each month. The problem is I am getting into a recursion that I don't want.

For example, say the user enters $5,000 for Feb, 2009. The Worksheet_Change
macro then updates the total for 2009 by adding all twelve months' data.
This causes another call to Worksheet_Change (because 2009 changed), which
then tries to spread the 2009 total amount amongst the months. And so on...

I would appreciate any suggestions for preventing this recursion, or even
another (probably easier and smarter) way to do this.

Thanks,

Eric
 
R

Ronald R. Dodge, Jr.

Yes, you can use the EnableEvent property on the Application object. When
your code first go into the event, set this property to False, then when
your code is done, set this property back to True.

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
 
E

egun

I learn something new every day! Thank you for your response - that was
exactly what I needed.

Eric
 

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