ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   prevent event procedure under condition (https://www.excelbanter.com/excel-programming/332960-prevent-event-procedure-under-condition.html)

short_n_curly

prevent event procedure under condition
 

is it possible to stop the selection change event procedure from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of event by
change but keeps looping when triggered
if the change would stop the selection code once activated it will
prevent any looping

hope this makes sense i would imagine it be something similar to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile: http://www.excelforum.com/member.php...o&userid=21576
View this thread: http://www.excelforum.com/showthread...hreadid=382587


Chip Pearson

prevent event procedure under condition
 
Use Application.EnableEvents = False to stop events from firing.
Set it back to true at the appropriate place in your code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"short_n_curly"

wrote in message
news:short_n_curly.1rau2l_1119899158.6547@excelfor um-nospam.com...

is it possible to stop the selection change event procedure
from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of
event by
change but keeps looping when triggered
if the change would stop the selection code once activated it
will
prevent any looping

hope this makes sense i would imagine it be something similar
to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile:
http://www.excelforum.com/member.php...o&userid=21576
View this thread:
http://www.excelforum.com/showthread...hreadid=382587




Jim Thomlinson[_4_]

prevent event procedure under condition
 
I am assuming that your selection change event code triggers a selection
change and that is resulting in a recursive call. To fix that you can set
application.enableEvents to ignore the events something like this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

ErrorHandler:
Application.EnableEvents = True
End Sub

As always when switching application settings it is safest to have an error
handler to reset the applicaton in case your code crashes...
--
HTH...

Jim Thomlinson


"short_n_curly" wrote:


is it possible to stop the selection change event procedure from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of event by
change but keeps looping when triggered
if the change would stop the selection code once activated it will
prevent any looping

hope this makes sense i would imagine it be something similar to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile: http://www.excelforum.com/member.php...o&userid=21576
View this thread: http://www.excelforum.com/showthread...hreadid=382587



Tom Ogilvy

prevent event procedure under condition
 
Just some added information:

Jim, either you mistyped or misread. He said the change event is causing a
selectionchange to fire.

In any event, while the solution is certainly applicable, a better all
around solution might be to avoid making a selection in the change event.
In other words, if the OP is using recorder style code like

Range("A1").Select
Selection.Value = 21
Range("B9").Select

then this should be avoided with just

range("A1").Value = 21

which doesn't trigger a selectionchange.

--
Regards,
Tom Ogilvy



"Jim Thomlinson" wrote in message
...
I am assuming that your selection change event code triggers a selection
change and that is resulting in a recursive call. To fix that you can set
application.enableEvents to ignore the events something like this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False

ErrorHandler:
Application.EnableEvents = True
End Sub

As always when switching application settings it is safest to have an

error
handler to reset the applicaton in case your code crashes...
--
HTH...

Jim Thomlinson


"short_n_curly" wrote:


is it possible to stop the selection change event procedure from being
triggered from within a worksheet change event code
i.e i have an event by slection that will begin the start of event by
change but keeps looping when triggered
if the change would stop the selection code once activated it will
prevent any looping

hope this makes sense i would imagine it be something similar to
either
exit private sub worksheet_selectionchange
or
end provate sub worksheet_selectionchange
however neither of these codes work

please help me thanks


--
short_n_curly
------------------------------------------------------------------------
short_n_curly's Profile:

http://www.excelforum.com/member.php...o&userid=21576
View this thread:

http://www.excelforum.com/showthread...hreadid=382587






All times are GMT +1. The time now is 01:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com