+ Reply to Thread
Results 1 to 4 of 4

prevent event procedure under condition

  1. #1
    Registered User
    Join Date
    03-27-2005
    Posts
    59

    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

  2. #2
    Chip Pearson
    Guest

    Re: 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"
    <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > 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
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: 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
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1