Consulting

Results 1 to 3 of 3

Thread: running two Worksheet_Change events

  1. #1

    running two Worksheet_Change events

    hello,

    i saw some code somewhere but cant find it for the life of me now but there was a piece of code written to work around ambigious Worksheet_Change.
    Whereby two worksheet change events were performed in the same piece of code. It went something like calling the first piece of code a name(say name 1), and the second another name(name 2).
    Then the piece of code preformed name 1 first then carried out name 2. Can anyone enlighten me ??

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    You could make each piece of code into a user-defined function (or Sub) and then as a part of the Change Event call them in the order you want them to run.

    Does that accomplish what you're trying to do?
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]


    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "H1:H10" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range("A1:A10")) Is Nothing Then
    With Target
    ' do one type of stuff
    End With
    ElseIf Not Intersect(Target, Me.Range("D510")) Is Nothing Then
    With Target
    ' do your other stuff
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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