Termination of macro based on cell values

R

robot

I have a macro that modifies cell values. I would like to terminate the
macro when certain cells' values meet some given conditions (say cell's
value > 10). How do I go about doing this? Suggestions are most welcome!

I use Excel 2007 and Windows 7 Home Premium. Thanks in advance.
 
J

Jim Cone

If cell's value > 10 then exit sub

"robot" <[email protected]>
wrote in message
I have a macro that modifies cell values. I would like to terminate the
macro when certain cells' values meet some given conditions (say cell's
value > 10). How do I go about doing this? Suggestions are most welcome!

I use Excel 2007 and Windows 7 Home Premium. Thanks in advance.
 
R

robot

Jim Cone said:
If cell's value > 10 then exit sub

"robot" <[email protected]>
wrote in message
I have a macro that modifies cell values. I would like to terminate the
macro when certain cells' values meet some given conditions (say cell's
value > 10). How do I go about doing this? Suggestions are most welcome!

I use Excel 2007 and Windows 7 Home Premium. Thanks in advance.

Thanks for the reply.

Maybe I wasn't making myself clear. My problem is that, it is not known when
and where the cells' value will meet the given conditions. And I hope to
terminate the macro whenever one (and not more than one) cell meets the
conditions.

I can use the worksheet_change event to trap the instance when such
conditions are met, but I don't know how to terminate the macro in the event
handler.
 
J

Jim Cone

The user can't enter data in a cell while code is running so the worksheet change event won't occur unless your code changes a cell.
So even if your code randomly picks a cell and assigns a random value, your code has the value assigned and which cell was picked.
On the other hand, if you start your code from within the event sub then "Target" is the cell(s) that changed, so...
If Target(1).Value > 10 then Exit Sub
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..

"robot" <[email protected]>
wrote in message
Thanks for the reply.
Maybe I wasn't making myself clear. My problem is that, it is not known when
and where the cells' value will meet the given conditions. And I hope to
terminate the macro whenever one (and not more than one) cell meets the
conditions.
I can use the worksheet_change event to trap the instance when such
conditions are met, but I don't know how to terminate the macro in the event
handler.
 

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