+ Reply to Thread
Results 1 to 24 of 24

Help with a VBA Code (Dropdown list)

  1. #1
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Help with a VBA Code (Dropdown list)

    Hello,

    The code in this example enable us to select multiple values from a dropdown list.

    However , for example, if I want to delete Q8- from the list in the 4th row and select another one I get an error message.

    Can anyone help with the VBA code?

    Thank you
    Attached Files Attached Files

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

    Re: Help with a VBA Code (Dropdown list)

    Try something like this...

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    Hello Alpha,

    First off all thank you for replying to this thread. I tried the code you gave. I am still not able to delete a value from the list and add new one without deleting the whole list.

    N.B: i removed the code i have and put yours.

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

    Re: Help with a VBA Code (Dropdown list)

    How are you trying to delete the value?

    If you re-select from the list a previously selected value, it is then removed. It seems to work for me in your example workbook.

  5. #5
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    hmm...I see your point. Your code is a solution actually.

    What i wanted is to delete from a list a certain value and then selecting another one from the dropdown list.

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

    Re: Help with a VBA Code (Dropdown list)

    Quote Originally Posted by Naja View Post
    hmm...I see your point. Your code is a solution actually.

    What i wanted is to delete from a list a certain value and then selecting another one from the dropdown list.
    How did you want to delete? You would have to be more specific.

    Otherwise, mark this as solved.

  7. #7
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    Hello,

    I entered your code, I am able to delete a value from the dropdown list BUT if I try to type anything in any cell, i get this error message :
    ''Error 9 Subscript out of range''.

    Can you fix it?

    Thank you

    Here is the file with the code you gave me Sample N with new code.xlsm

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

    Re: Help with a VBA Code (Dropdown list)

    I cannot replicate the error with the file you provided. In several cells I typed, deleted, copied. Everything I tried produced no errors.

    Does the error message have the title "ERROR: Worksheet_Change procedure"?

    Does the error message have a Debug button? If yes, is a line of code highlighted when you click it?

    Also, no need to PM me. I get notified when you reply to this thread.

  9. #9
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    Hello Alpha,

    Yes the error has the title "ERROR: Worksheet_Change procedure".
    But it doesn't have a Debug Button.

    Thank you

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

    Re: Help with a VBA Code (Dropdown list)

    To help diagnose, comment out the error handler code (below). Then does the error message now have a debug button and if yes, what line is highlighted.

    Note: you will have to re-enable Application.Events after the error.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    I did that. Now i cannot choose multiple values from the dropdown list...

    Here is the new file with the your new code

    Sample N with new code3.xlsm

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

    Re: Help with a VBA Code (Dropdown list)

    You only pasted part of the code to the new file.

    All this is missing...
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    Done Sample N with new code4.xlsm

    I still cannot choose mutliple values... and no error message

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

    Re: Help with a VBA Code (Dropdown list)

    Note: you will have to re-enable Application.Events.

    Put this code in a standard code module (e.g.; Module1) and run it.

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    I am a little confused..
    But i think i did that. Have a look Sample N with new code4.xlsm

    I got nothing.

    N.B: thank you so much for trying to figure this out with me

  16. #16
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    What if we try in the code make a direct reference to the activie sheet or something like that?

  17. #17
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    What if we try to make a reference to the activite sheet?

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

    Re: Help with a VBA Code (Dropdown list)

    Quote Originally Posted by Naja View Post
    What if we try in the code make a direct reference to the activie sheet or something like that?

    What if we try to make a reference to the activite sheet?
    Not needed and also not needed the 2nd time and for future reference it wont be needed.

    Close Excel completely and restart it and open only the last version of the workbook (code4).

  19. #19
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    Not working..

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

    Re: Help with a VBA Code (Dropdown list)

    My mistake. Don't comment out the last line. Then run the Re-Enable_Events macro once.

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    Now it is working Weird..
    But can you please the solution Alpha? Why did we comment out that particular line??

    n.b: what do you recommend me to do to ameliorate myself in vba coding? Do suggest anybooks?

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

    Re: Help with a VBA Code (Dropdown list)

    I don't know what caused your error in the first place. I couldn't replicate it. I don't know why it is not erring now. We didn't fix anything. All we did was disable the error checker so we might see what line caused the error should it happen again. If you do get an error now, you will have to ReEnabel_Events for the code to work again.

    I don't have any specific recommendation for books. Check out the sticky thread at the top of this forum.

  23. #23
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Help with a VBA Code (Dropdown list)

    It is working perfectly actually. I can select multiple values from the dropdown list and write in any cell without the Error 9 message.

    How do I ReEnabel_Events ?

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

    Re: Help with a VBA Code (Dropdown list)

    run the Re-Enable_Events macro once.

+ 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