+ Reply to Thread
Results 1 to 33 of 33

Compile error: Ambiguous name detected: Worksheet_Change

  1. #1
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Compile error: Ambiguous name detected: Worksheet_Change

    Hi all,

    Im having a problem.. Ive never used Visual Basic and I am trying to copy and paste some code in that formats cells so I dont have to type "/" or ":" while entering dates and times. I know the code isnt working because I have "Private Sub Worksheet_Change(ByVal Target As Excel.Range)" typed in twice, but I just dont know what to type to make this work. I put in arrows to show where the error is. Any help would be greatly appreciated!

    Please Login or Register  to view this content.
    Last edited by ericwilder; 01-21-2013 at 03:28 PM.

  2. #2
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    First off , your code should be placed in coe tags
    Second for your problem as Excel.Range , remove Excel. , as Range willwork fine

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Eric,
    Please use code tags in your code. You can edit the above code by the following:

    Choose-Edit-highlight the whole code and then click# (from the menu)
    Or
    Code[ ]
    your code
    Code[ ]

  4. #4
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Thank you for your help hulpeloos!! Im sorry I didnt understand what you meant by "your code should be placed in coe tags"

  5. #5
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    I entered this "Private Sub Worksheet_Change(ByVal Target As Range)" as my second macro name... but it still returns the same error message.. What do I need to re name this thing to get it to work?

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    [CODE]

    ''''' your code goes in here

    [CODE]

  7. #7
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Quote Originally Posted by ericwilder View Post
    I entered this "Private Sub Worksheet_Change(ByVal Target As Range)" as my second macro name... but it still returns the same error message.. What do I need to re name this thing to get it to work?
    wait ... you have attempted to have both subs right under eachother in the same VBA-code sheet ?
    You can normally put all your codin into 1 "Private Sub Worksheet_Change(ByVal Target As Range)"

  8. #8
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Yea i just tried to combine two different codes I found online that I wanted to work for the same spreadsheet. I dont know how to put them together...
    Last edited by ericwilder; 01-19-2013 at 04:01 PM.

  9. #9
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    in theory you can join them by remove the 2 bold lines below as indicated

    Please Login or Register  to view this content.
    HOWEVER you will havea lot off duplicates that will break the code , so you will have to rename everything in the second part , for example

    in first part you have
    Please Login or Register  to view this content.
    So in second part you have to rename the same instacnes to
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Thanks so much for your reply! however I am not seeing any bold text, to clarify, do you want me to delete
    "End Sub"

    and

    "Private Sub Worksheet_Change(ByVal Target As Excel.Range) <---------------------------"

  11. #11
    Forum Contributor
    Join Date
    01-17-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    211

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    yes thats correct

  12. #12
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Maybe change the names of the two subs:
    WS_ChangeONE
    WS_ChangeTWO
    Then use this :
    Please Login or Register  to view this content.
    That would save a lot of renaming of variables etc .
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi ericwilde

    Show us what you have and what you'd like it to be...perhaps we can help.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  14. #14
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Okay, in order to avoid having to change duplicate names I took a stab at what dredwolf suggested. Heres what it looks like now.. It still isn't working though. Please look over it and let me know where I messed this up.

    Please Login or Register  to view this content.

  15. #15
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    you still need the (ByVal Target as Range ) for the other 2 subs is what I notice right away.. since I'm not sure what the 2 Subs are suppoesed to do, I'm not sure if there is any problems within them

    But if you change the sub definitions as above, They should at least show a different error..
    Hope this helps

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi ericwilde

    Post a sample workbook Please attach a sample file that represents what you have. The structure of your attachment should be the same structure as your actual data. Any proprietary information should be changed.

    Include in the attachment any code you're currently using (whether it works or not) and an "After" worksheet that demonstrates what you wish the output to be.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the "Add Files"... button to locate your file for uploading.
    6. This will open a new window File Upload...Click "Select Files"
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the "Upload Files" button and wait until the file has uploaded.
    10. Click the "Done" Button.

  17. #17
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Okay I will post the sample WB
    Last edited by ericwilder; 01-21-2013 at 11:03 AM.

  18. #18
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    One Sheet to Rule Them All.xls

    The purpose of the sheet is to allow me to enter dates and times without entering "/"'s or ":"'s

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi ericwilder

    This code will ONLY work if you condition yourself to ALWAYS enter the DATE portion of the string with 6 (SIX) digits (eg: 011298 for January 12, 1998 or 121298 for December 12, 1998).
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Thank you! However there seems to be a small issue with the code. The date appears just fine when the date and time is entered- but in the cell the time does not show up (it does in the formula bar). Expanding the cell did nothing to fix the problem. Please advise.

    Also, four digit time values result in an error.
    Last edited by ericwilder; 01-21-2013 at 03:14 PM.

  21. #21
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi ericwilder

    See attached...let me know of issues.
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Ive re-uploaded the WB. I hope this helps.
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    You truly are a guru. I hope one day to possess a fraction of your skills. Thank you for your help.

  24. #24
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi ericwilder

    For the moment let's deal with the Workbook I uploaded...what's the Code doing or not doing that you wish it to?

    Thanks for the compliment.

  25. #25
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    It seems to be working. I was entering spaces between the date and time which I believe is what was messing it up. The last question I have is this: if I wanted to make it so that this macro worked for both the A and B colums, what would I enter?

    Would this work?

    Please Login or Register  to view this content.

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi ericwilder

    You can do this one of two ways (probably more).
    Please Login or Register  to view this content.
    If your dealing with the entire Columns then perhaps this
    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Okay, so I've been trouble shooting the code and there are still some glitches. It will not allow me to enter times later than 12:59. I tried entering 13:00 and it gave me the error msg. Im going to attach the sheet that I was planning to transplant the code into and let you take a better look. I wanted this code to work for columns A and B. I originally thought "this shouldn't be too hard" (how wrong I was).
    Attached Files Attached Files

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi eric

    In your Logging File do you Filter on Columns A & B? If so...how? Details please...

  29. #29
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    I have filters on both colums but I just checked with some co workers, and they are not vital and so I have removed them. I entered both versions of the code you provided that expand the macro to the A and B column, and it does not seem to be working. The A colum still operates but the B column does not work.
    Last edited by ericwilder; 01-22-2013 at 12:18 PM.

  30. #30
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    on an unrelated note.. how the heck do I delete a post?! Excel Forum is only letting me edit posts (this was originally an extraneous post I wanted to delete but could not).
    Last edited by ericwilder; 01-22-2013 at 12:25 PM.

  31. #31
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi eric

    One of the issues is the Formatting of Columns A & B in your file Logging File...that's why I asked about the Filtering of these columns. I'll look at it later this morning...have it working on my platform (if Filtering on Columns A & B is not an issue)...want do do more testing.

  32. #32
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hi eric

    Regarding this
    how the heck do I delete a post
    You can't...only Edit. Moderators can delete posts...you'll need to ask them to do so.

    Regarding my additional testing...what the hey...you can do that. The attached file has Columns A & B formatted as text...it seems to work on both Columns for me. Let me know of issues.
    Attached Files Attached Files

  33. #33
    Registered User
    Join Date
    01-19-2013
    Location
    salt lake city, utah
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Compile error: Ambiguous name detected: Worksheet_Change

    Hey, is there a way to modify the macro so it stays in military time after it is entered? Currently it reverts to standard time.

    Thanks again,
    Eric

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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