+ Reply to Thread
Results 1 to 4 of 4

Worksheet with Multiple Worksheet Changes

Hybrid View

  1. #1
    Registered User
    Join Date
    12-03-2015
    Location
    Sydney
    MS-Off Ver
    windows7
    Posts
    8

    Worksheet with Multiple Worksheet Changes

    Hi
    I have a worksheet which I would like to add 3 different change requests as per below
    I get below message so I gather this may not be possible

    Compile error:
    Ambiguous name detected: Worksheet_change


    Does anyone have any tips on how to get around this.
    I am only new to Excel code so help much appreciated

    Thanks
    Rocco


    CODE
    ----------------------------------------------------------------------------------------------------------------
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim v As Variant

    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("C16:C29")) Is Nothing Then Exit Sub 'specific range

    'Turn off events to keep out of loops
    Application.EnableEvents = False

    v = Application.Match(Target.Value, Worksheets("Lists").Range("B:B"), False)

    If Not IsError(v) Then
    Target.Value = Worksheets("Lists").Range("A:A").Cells(v).Value
    End If

    'Turn events back on to get ready for the next change
    Application.EnableEvents = True
    End Sub
    ----------------------------------------------------------------------------------------------------------------
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim v As Variant

    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("G16:G29")) Is Nothing Then Exit Sub 'specific range

    'Turn off events to keep out of loops
    Application.EnableEvents = False

    v = Application.Match(Target.Value, Worksheets("Lists").Range("F:F"), False)

    If Not IsError(v) Then
    Target.Value = Worksheets("Lists").Range("E:E").Cells(v).Value
    End If

    'Turn events back on to get ready for the next change
    Application.EnableEvents = True
    End Sub
    ----------------------------------------------------------------------------------------------------------------
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim v As Variant

    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("H16:H29")) Is Nothing Then Exit Sub 'specific range

    'Turn off events to keep out of loops
    Application.EnableEvents = False

    v = Application.Match(Target.Value, Worksheets("Lists").Range("I:I"), False)

    If Not IsError(v) Then
    Target.Value = Worksheets("Lists").Range("H:H").Cells(v).Value
    End If

    'Turn events back on to get ready for the next change
    Application.EnableEvents = True
    End Sub
    Quote ReplyReport Edit

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,204

    Re: Worksheet with Multiple Worksheet Changes

    For each one, you need to change this:

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim v As Variant
    
    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("C16:C29")) Is Nothing Then Exit Sub 'specific range
    
    'Turn off events to keep out of loops
    Application.EnableEvents = False
    
    v = Application.Match(Target.Value, Worksheets("Lists").Range("B:B"), False)
    
    If Not IsError(v) Then
    Target.Value = Worksheets("Lists").Range("A:A").Cells(v).Value
    End If
    
    'Turn events back on to get ready for the next change
    Application.EnableEvents = True
    End Sub
    To this:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim v As Variant
    
    If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C16:C29")) Is Nothing Then ' Exit Sub 'specific range
    
    'Turn off events to keep out of loops
    Application.EnableEvents = False
    
    v = Application.Match(Target.Value, Worksheets("Lists").Range("B:B"), False)
    
    If Not IsError(v) Then
    Target.Value = Worksheets("Lists").Range("A:A").Cells(v).Value
    End If
    
    'Turn events back on to get ready for the next change
    Application.EnableEvents = True
    End If
    End Sub
    And combine into one event handler.

    You will only need this once:

    Dim v As Variant
    
    If Target.Cells.Count > 1 Then Exit Sub
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    12-03-2015
    Location
    Sydney
    MS-Off Ver
    windows7
    Posts
    8

    Re: Worksheet with Multiple Worksheet Changes

    Thanks for that work great much appreciated

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,204

    Re: Worksheet with Multiple Worksheet Changes

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Retrieving multiple cell info from a worksheet 2 and show results on worksheet 1
    By dave57 in forum Excel Formulas & Functions
    Replies: 27
    Last Post: 05-25-2017, 08:32 AM
  2. Replies: 13
    Last Post: 10-05-2015, 08:59 AM
  3. Macro to copy data from multiple worksheet cells in to a single Master worksheet
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2015, 03:24 PM
  4. Merge multiple worksheet to summary worksheet based on column header value match
    By rafiomeon in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-23-2012, 03:37 AM
  5. plot graph from multiple worksheet as embedded chart object on every worksheet
    By Jeffrey.Tiong@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2006, 05:45 PM
  6. plot graph from multiple worksheet as embedded chart object on every worksheet
    By Jeffrey.Tiong@gmail.com in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-22-2006, 05:45 PM
  7. Replies: 3
    Last Post: 03-12-2006, 06:00 AM

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