+ Reply to Thread
Results 1 to 10 of 10

Ambiguous name detected error

Hybrid View

jpxexcelforum Ambiguous name detected error 09-07-2011, 04:25 PM
TMS Re: Ambiguous name detected... 09-07-2011, 04:37 PM
jpxexcelforum Re: Ambiguous name detected... 09-07-2011, 04:47 PM
TMS Re: Ambiguous name detected... 09-07-2011, 04:59 PM
TMS Re: Ambiguous name detected... 09-07-2011, 05:03 PM
jpxexcelforum Re: Ambiguous name detected... 09-07-2011, 05:15 PM
TMS Re: Ambiguous name detected... 09-07-2011, 05:28 PM
TMS Re: Ambiguous name detected... 09-07-2011, 05:35 PM
jpxexcelforum Re: Ambiguous name detected... 09-07-2011, 06:00 PM
romperstomper Re: Ambiguous name detected... 09-07-2011, 06:04 PM
  1. #1
    Registered User
    Join Date
    10-10-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    34

    Ambiguous name detected error

    Why do I have that error?


    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    
    If Target.Column = 19 And Target <> "" Then
        If Target.Offset(0, 4) = "" Then Target.Offset(0, 4).Value = Now
    End If
    
    If Target.Column = 19 And Target = "" Then
        Target.Offset(0, 4).ClearContents
    End If
    
    End Sub
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Target.Column = 5 And Target <> "" Then
        If Target.Offset(0, 18) = "" Then Target.Offset(0, 18).Value = Now
    End If
    
    If Target.Column = 5 And Target = "" Then
        Target.Offset(0, 18).ClearContents
    End If
    
    End Sub
    Last edited by jpxexcelforum; 09-10-2011 at 03:09 PM.

  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,208

    Re: Ambiguous name detected error

    It's ambiguous because you have *two* "Private Sub Workbook_SheetChange" events.

    You need to combine the tests within one "Private Sub Workbook_SheetChange" event.

    Regards
    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
    10-10-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Ambiguous name detected error

    Quote Originally Posted by TMShucks View Post
    It's ambiguous because you have *two* "Private Sub Workbook_SheetChange" events.

    You need to combine the tests within one "Private Sub Workbook_SheetChange" event.

    Regards
    Can you show me how? I'm new to coding.

  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,208

    Re: Ambiguous name detected error

    One way:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    
    If Target.Column = 19 And Target <> "" Then
        If Target.Offset(0, 4) = "" Then Target.Offset(0, 4).Value = Now
        Exit Sub
    End If
    
    If Target.Column = 19 And Target = "" Then
        Target.Offset(0, 4).ClearContents
        Exit Sub
    End If
    
    If Target.Column = 5 And Target <> "" Then
        If Target.Offset(0, 18) = "" Then Target.Offset(0, 18).Value = Now
        Exit Sub
    End If
    
    If Target.Column = 5 And Target = "" Then
        Target.Offset(0, 18).ClearContents
        Exit Sub
    End If
    
    End Sub

    Regards

  5. #5
    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,208

    Re: Ambiguous name detected error

    In actual fact, each section should be structured like:

    If Target.Column = 19 And Target <> "" Then
        If Target.Offset(0, 4) = "" Then 
            Application.EnableEvents = False
            Target.Offset(0, 4).Value = Now
            Application.EnableEvents = True
        End If
        Exit Sub
    End If

    This is because you are making changes to the sheet within the change event.


    Regards

  6. #6
    Registered User
    Join Date
    10-10-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Ambiguous name detected error

    Thanks. The first one didn't work though, I tried it. I tried the second one. Is this correct?

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    
    If Target.Column = 19 And Target <> "" Then
        If Target.Offset(0, 4) = "" Then
            Application.EnableEvents = False
            Target.Offset(0, 4).Value = Now
            Application.EnableEvents = True
        End If
        Exit Sub
    End If
    
    If Target.Column = 5 And Target <> "" Then
        If Target.Offset(0, 18) = "" Then
            Application.EnableEvents = False
            Target.Offset(0, 18).Value = Now
            Application.EnableEvents = True
        End If
        Exit Sub
    End If
    
    End Sub

  7. #7
    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,208

    Re: Ambiguous name detected error

    In what way didn't it work?

    I would have expected it to work but it would have gone through the routine more times than it needed to.

    The second example looks OK ... but, if the first attempt failed, I don't see why this would be any more successful.

    Regards

  8. #8
    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,208

    Re: Ambiguous name detected error

    This works as I would expect it to:

    Option Explicit
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Target.Column = 19 And Target <> "" Then
        If Target.Offset(0, 4) = "" Then
            Application.EnableEvents = False
            Target.Offset(0, 4).Value = Now
            Application.EnableEvents = True
        End If
        Exit Sub
    End If
    
    If Target.Column = 19 And Target = "" Then
        Application.EnableEvents = False
        Target.Offset(0, 4).ClearContents
        Application.EnableEvents = True
        Exit Sub
    End If
    
    If Target.Column = 5 And Target <> "" Then
        If Target.Offset(0, 18) = "" Then
            Application.EnableEvents = False
            Target.Offset(0, 18).Value = Now
            Application.EnableEvents = True
        End If
        Exit Sub
    End If
    
    If Target.Column = 5 And Target = "" Then
        Application.EnableEvents = False
        Target.Offset(0, 18).ClearContents
        Application.EnableEvents = True
        Exit Sub
    End If
    
    End Sub


    Regards

  9. #9
    Registered User
    Join Date
    10-10-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Ambiguous name detected error

    Works great! I saw where I made a mistake. I linked a cell to the same offset. This is exactly what I needed.

    Thanks a lot! Mods please consider this thread solved! Thanks again TMShucks!!

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Ambiguous name detected error

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

    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
    Everyone who confuses correlation and causation ends up dead.

+ 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