+ Reply to Thread
Results 1 to 10 of 10

dynamic dropdown list, VBA

  1. #1
    Registered User
    Join Date
    08-22-2014
    Location
    Swiss
    MS-Off Ver
    2010
    Posts
    12

    dynamic dropdown list, VBA

    Hi Folks

    I have created a cell with a dynamic dropdown-list via data validation, which changes its range, depending on the value in another static dropdown-list.(works fine)

    Appearently it is a common problem, that the cell keeps the last value that was selected from the previous range. So I have to manually select the dropdown and select one of the now available values.
    This seems to happen because the change of range happens due to mouse-selection and not via direct input. A humongous paperchase on goolge concluded, that I'd have to use some VBA to bypass this.

    So what I basically want is for the dynamic-list-cell to be cleared if the Value of the static list changes.
    How I thought to achieve this:

    Cell1 = Dropdown list(static) [Value1, Value2, Value3]
    Cell2 = Dropdown list(dynamic)
    Cell3 = Variable Value

    Pseudo code:
    If Cell3 unequal to Cell1 then
    1. clear Cell2;
    2. Copy Value of Cell1 into Cell3 //So the condition is no longer met until Cell1 is changed
    else do nothing

    I'm absolutely new to VBA but I tried this:

    Please Login or Register  to view this content.
    The debugger marks the second row yellow.

    Can someone make this work please?

  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
    44,422

    Re: dynamic dropdown list, VBA

    The code looks OK but you don't need ".Select ... Selection."

    Please Login or Register  to view this content.
    However, you would be better off with a Worksheet Change event handler monitoring cell A1. When A1 changes, clear cell A2, etc.

    For more specific help, please upload a sample workbook.


    Regards, TMS
    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
    08-22-2014
    Location
    Swiss
    MS-Off Ver
    2010
    Posts
    12

    Re: dynamic dropdown list, VBA

    Hello

    Thank you for the fast reply.
    I made an example sheet, but I don't know how to put it in here so you can download it.

    What I also don't know is how the VBA script runs. Isn't it a continuous loop?
    Also I wonder, if my PC and office programs are set to german-language and all the function-names in excel are german, would the VBA-script also require german expressions?

  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
    44,422

    Re: dynamic dropdown list, VBA

    A Worksheet Change event handler, if present, runs continuously in the background and fires whenever a change is made on the monitored sheet. It is normal practice to restrict the cells monitored to just those "of interest"; in this case, probably cell A1.


    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  5. #5
    Registered User
    Join Date
    08-22-2014
    Location
    Swiss
    MS-Off Ver
    2010
    Posts
    12

    Re: dynamic dropdown list, VBA

    OK, I figured out that Worksheet_Calculate only triggers when an actual calculation is processed.
    The script then works perfectly fine.
    So the Worksheet_-Funktion is a condition under what the code underneath is being triggered?
    Therefore your suggestion of Worksheet_change would mean that if anything in the worksheet changes, the code would be triggered, right?
    With this assumption I changed the code to this:

    Please Login or Register  to view this content.
    If I now change Cell1, I get:
    Runtime error '-2147417848 (80010108)'
    The method 'ClearContents' failed for Object 'Range'.

    (For me it is actually written in german)

  6. #6
    Registered User
    Join Date
    08-22-2014
    Location
    Swiss
    MS-Off Ver
    2010
    Posts
    12

    Re: dynamic dropdown list, VBA

    Ok here's the example sheet. It follows the explaination in my first post.
    Like I said with Worksheet_Calculate it would work fine.
    I don't know if the language matters.
    Attached Files Attached Files

  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
    44,422

    Re: dynamic dropdown list, VBA

    Please Login or Register  to view this content.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    08-22-2014
    Location
    Swiss
    MS-Off Ver
    2010
    Posts
    12

    Re: dynamic dropdown list, VBA

    Wonderful! Thank you very much.
    I just hope I can reproduce this for my real sheet.

  9. #9
    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
    44,422

    Re: dynamic dropdown list, VBA

    You're welcome.


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


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    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


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  10. #10
    Registered User
    Join Date
    08-22-2014
    Location
    Swiss
    MS-Off Ver
    2010
    Posts
    12

    Re: dynamic dropdown list, VBA

    Thanks for the advice.

+ 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. [SOLVED] Dynamic Dropdown from a list made with formulas.
    By JO505 in forum Excel General
    Replies: 6
    Last Post: 04-30-2014, 08:54 AM
  2. Dynamic Dropdown Menu/List
    By liampog in forum Excel General
    Replies: 4
    Last Post: 08-22-2013, 08:35 PM
  3. dynamic dropdown list of dates
    By sherlock99 in forum Excel General
    Replies: 1
    Last Post: 08-09-2013, 08:06 AM
  4. Excel 2007 : Dynamic dropdown list
    By Mikme Riley in forum Excel General
    Replies: 2
    Last Post: 05-09-2012, 04:45 PM
  5. Dynamic dropdown list quandry
    By Shocked in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-11-2008, 09:58 AM

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