+ Reply to Thread
Results 1 to 4 of 4

Change Event Endless loop :-(

Hybrid View

  1. #1

    Change Event Endless loop :-(

    Hi everybody: I have a macro that triggers other macros depending which
    column has changed. The problem is that it enters in an endless because
    the other macros change columns again and I enter an endless loop...

    As you can see, this macro starts whith a change event

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim C As Long
    C = Target.Column
    Select case
    Case is =1
    Call Macro1
    Case is =2
    Call Macro2
    End Select
    End Sub

    Sub Macro 1()
    Range("a1").value=100
    'Rest of the code here...
    'As you can see, this macro change Column 1 so it triggers again the
    change event (endless loop)
    End Sub

    Sub Macro 2()
    Range("b1").value=200
    'Rest of the code here...
    'As you can see, this macro change Column 2 so it triggers again the
    change event (endless loop)
    End Sub

    Can you suggest me any code to avoid the endless loop?

    Thank you very much !

    ---


  2. #2
    Registered User Ivan F Moala's Avatar
    Join Date
    10-25-2003
    Location
    Auckland, New Zealand
    Posts
    71
    Wrap your code within the Enableevents eg

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim C As Long
    C = Target.Column

    application.enableevents=false

    Select case
    Case is =1
    Call Macro1
    Case is =2
    Call Macro2
    End Select

    application.enableevents=true

    End Sub
    Kind Regards,
    Ivan F Moala From the City of Sails
    \1

  3. #3
    JE McGimpsey
    Guest

    Re: Change Event Endless loop :-(

    One way:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim C As Long
    On Error GoTo Err_Handler
    Application.EnableEvents = False
    '...rest of your macro
    Err_Handler:
    Application.EnableEvents = True
    On Error GoTo 0
    End Sub

    In article <[email protected]>,
    [email protected] wrote:

    > Hi everybody: I have a macro that triggers other macros depending which
    > column has changed. The problem is that it enters in an endless because
    > the other macros change columns again and I enter an endless loop...
    >
    > As you can see, this macro starts whith a change event
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim C As Long
    > C = Target.Column
    > Select case
    > Case is =1
    > Call Macro1
    > Case is =2
    > Call Macro2
    > End Select
    > End Sub
    >
    > Sub Macro 1()
    > Range("a1").value=100
    > 'Rest of the code here...
    > 'As you can see, this macro change Column 1 so it triggers again the
    > change event (endless loop)
    > End Sub
    >
    > Sub Macro 2()
    > Range("b1").value=200
    > 'Rest of the code here...
    > 'As you can see, this macro change Column 2 so it triggers again the
    > change event (endless loop)
    > End Sub
    >
    > Can you suggest me any code to avoid the endless loop?
    >
    > Thank you very much !
    >
    > ---


  4. #4

    Re: Change Event Endless loop :-(

    Thank you very much botn IVAN F MOALA and JE McGimpsey . Your solutions
    are perfect and I have solve the problem...

    CONGRATULATIONS !!!


+ 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