VBA how to avoid target looping?

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,185
Hi,

I have the targets that run my macros spread on 3 column (A,B,C let's say). My problem is that if you select a specific value (Product 123 for example) in A, B, or C (let's say B in this example) I need to put product 123 in A & C: a message pops up to ask if user wants this, if he says yes, the macro writes Product 123 in A which get's the message to come again to ask userif he wants to put the values in other B&C, which will again affect a target...etc.

Is there a way to tell excell to stop considering the 3 column as target when user click yes? Any other workaround?
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You can use:

Application.EnableEvents = False

Prior to changing the value, which will stop recursion. Just make sure to set it back to True at the end.

HTH,
 
Upvote 0
Turn off Events prior to any line of code that changes the value of cells.

Application.EnableEvents = False

Make sure to set it back to TRUE at the end of your code.
Also wise to use an error handler

Rich (BB code):
Application.EnableEvents = False
On Error GoTo hndlr

'rest of your code goes here


'At the very end of the code put
hndlr:
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

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