+ Reply to Thread
Results 1 to 6 of 6

Compile error: Ambiguous name detected

Hybrid View

  1. #1
    Registered User
    Join Date
    06-05-2008
    Posts
    3

    Compile error: Ambiguous name detected

    Hi All,
    I searched the forums and i didnt see a topic like this so here it goes
    I am trying to program excel so that when someone enters a number the next cell will automatically enter the date and time. I figured it out for the first 2 columns but the subject error comes up for the next columns.
    I am attaching the file just in case i screwed up my explanation
    Update: i actually did see a thread with this topic.. but im still confused
    Thanks


    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    
            With Target
    
                If .Count > 1 Then Exit Sub
    
                If Not Intersect(Range("A2:A30"), .Cells) Is Nothing Then
    
                    Application.EnableEvents = False
    
                    With .Offset(0, 1)
    
                        .NumberFormat = "dd mmm yyyy hh:mm:ss"
    
                        .Value = Now
    
                    End With
    
                    Application.EnableEvents = True
    
                End If
    
            End With
    
        End Sub

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    
            With Target
    
                If .Count > 1 Then Exit Sub
    
                If Not Intersect(Range("D2:D30"), .Cells) Is Nothing Then
    
                    Application.EnableEvents = False
    
                    With .Offset(0, 1)
    
                        .NumberFormat = "dd mmm yyyy hh:mm:ss"
    
                        .Value = Now
    
                    End With
    
                    Application.EnableEvents = True
    
                End If
    
            End With
    
        End Sub
    Attached Files Attached Files
    Last edited by VBA Noob; 06-05-2008 at 02:18 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    You need to have your Worksheet_change macro sitting in the VBA tab for the sheet for which it is intended to operate and not in a normal module as well.

    In this case, it looks like the code needs to be in the Sheet1 tab and be removed from Module2.

  3. #3
    Registered User
    Join Date
    06-05-2008
    Posts
    3
    Quote Originally Posted by mrice
    You need to have your Worksheet_change macro sitting in the VBA tab for the sheet for which it is intended to operate and not in a normal module as well.

    In this case, it looks like the code needs to be in the Sheet1 tab and be removed from Module2.
    Thank you MRICE!
    but i still get the same error... and it highlightes the line
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)..
    any thoughts?

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Try the attached...
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-05-2008
    Posts
    3
    Quote Originally Posted by mrice
    Try the attached...
    Thank you again MRICE
    this is actually what i had in the begining. the problem that i am having is that if i want to do the same thing in the released column it doesnt work. and thats when i get the error screen

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Aletha,

    Try one copy of this in the sheet module:
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        With Target
            If .Count > 1 Then Exit Sub
            
            If Not Intersect(Range("A2:A30, D2:D30"), .Cells) Is Nothing Then
                Application.EnableEvents = False
                With .Offset(0, 1)
                    .NumberFormat = "dd mmm yyyy hh:mm:ss"
                    .Value = Now
                End With
                Application.EnableEvents = True
            End If
        End With
    End Sub

+ 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. Compile Error: Ambiguous Name Detected: Workbook_Open
    By Gos-C in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-19-2008, 10:46 AM
  2. Compile Error: Invalid Qualifier in column sum/cell naming program
    By xioncrush in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-09-2007, 12:35 AM
  3. Compile Error - Can't find project or Library
    By bmasella in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2007, 07:55 PM
  4. Compile Error?!?
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2007, 12:44 PM
  5. Ambiguous name detected - please help
    By umax in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2006, 08:26 PM

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