+ Reply to Thread
Results 1 to 15 of 15

VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

  1. #1
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Good Morning/Night all,

    I hope you folks are all well.

    I was wondering if anyone could please help me. I currently have the following code on my sheet:

    Please Login or Register  to view this content.
    It basically looks at the selected drop down list name in column 24 (X) and then changes it to a code (by going to another worksheet, matching and returning the code).

    But the problem is when an invalid name is entered (one that cannot be matched) then the sheets goes into an error mode i.e that annoying end debug msg box.

    Is there anyway to change the code so that the cell can accepts names that it can't match up with, so it doesn't go into error mode?

    Thank you in advance for you help guys, much appreciated .
    Last edited by f41yaz; 10-11-2018 at 09:25 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Thank you AlphaFrog, you're a legend!!! Works perfectly

    I have another related issue that has come about from this if you could please help me on (or anyone else)...

    So I also have the following code:

    Please Login or Register  to view this content.

    it basically automatically says "please select name" on the dependant drop down list cell whenever the primary drop down list is changed, in order to prevent the old selection staying there. This works perfectly fine when a drop down selection is selected but when text is entered manually then nothing happens.

    Is there a solution to this?

    Many thanks for your help!
    Last edited by f41yaz; 10-11-2018 at 09:25 AM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Welcome to the forum.

    Please take a few minutes to read the forum rules, and then edit your posts to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    After you edit the above posts and add CODE tags, show the code for the entire procedure. Context matters.

  6. #6
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Quote Originally Posted by AlphaFrog View Post
    After you edit the above posts and add CODE tags, show the code for the entire procedure. Context matters.
    As follows:

    Please Login or Register  to view this content.
    Let me know if you need anything else.

    Thanks mate, much appreciated.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Quote Originally Posted by f41yaz View Post
    Thank you AlphaFrog, you're a legend!!! Works perfectly

    I have another related issue that has come about from this if you could please help me on (or anyone else)...

    So I also have the following code:

    Please Login or Register  to view this content.

    it basically automatically says "please select name" on the dependant drop down list cell whenever the primary drop down list is changed, in order to prevent the old selection staying there. This works perfectly fine when a drop down selection is selected but when text is entered manually then nothing happens.

    Is there a solution to this?

    Many thanks for your help!
    It should work when you enter text manually. You would have to hit enter or select another cell after you enter the text.

  8. #8
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Quote Originally Posted by AlphaFrog View Post
    It should work when you enter text manually. You would have to hit enter or select another cell after you enter the text.
    It doesn't seem to work. After some investigation it seems like the following code is causing the problem.

    Please Login or Register  to view this content.
    I have attached a sample file. Please have a look when you have chance. Thanks!
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    You have three versions of the code that don't match. The code in post #6 has If Target.Column = 25 Then which is not in the same column as X25. That code should have worked. Then you changed it to If Target.Column = 24 Then which does conflict with the X25 column. Then your example workbook is completely different. This doesn't make it easy to help you.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Quote Originally Posted by AlphaFrog View Post
    You have three versions of the code that don't match. The code in post #6 has If Target.Column = 25 Then which is not in the same column as X25. That code should have worked. Then you changed it to If Target.Column = 24 Then which does conflict with the X25 column. Then your example workbook is completely different. This doesn't make it easy to help you.

    Please Login or Register  to view this content.
    Apologies for that! I thought it would be easier making a sample file but that clearly was the wrong thing to do. Sorry for wasting your time and I appreciate all your help.

    Here is the full code:

    Please Login or Register  to view this content.


    Thanks
    Last edited by f41yaz; 10-16-2018 at 04:45 AM.

  11. #11
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Sony to trouble you but any chance you can help me with editing the full code?

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Thanks but now the Drop Down Changes Name to Code for X21 is not working. Although it works for the other cells in that column. Any idea?

    I really appreciate your help.

  14. #14
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    09-12-2018
    Location
    Leicester
    MS-Off Ver
    2007onwards
    Posts
    32

    Re: VBA - Drop Down Changes Name to Code but Debug when invalid name is entered

    Thank you very much!!!

+ 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. Debug code
    By Human2014 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-03-2016, 07:27 PM
  2. Replies: 11
    Last Post: 11-10-2015, 07:13 PM
  3. VBA Code Runs in Debug Mode But Returns Type Mismatch Error Outside Debug Mode
    By valerie.k.chiang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2014, 03:48 PM
  4. [SOLVED] Debug: How to debug this code?
    By reach78 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-25-2013, 07:16 AM
  5. [SOLVED] VBA Debug (compile error invalid or unqualified reference)
    By Kezwick in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 04:38 AM
  6. Debug the Code
    By macrogeek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2011, 06:45 AM
  7. HELP, trying to debug this code...
    By twofootgiant in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2011, 12:05 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