+ Reply to Thread
Results 1 to 6 of 6

Question about manipulating list box value in VBA

  1. #1
    Registered User
    Join Date
    05-11-2007
    Posts
    93

    Question Question about manipulating list box value in VBA

    Hi all,
    I want to know ways by which i can change the List box option in excel using VB.
    For eg. : I have a drop down called "Info" and has values a,b,c and have another drop down called "Flag" and has values Yes and no.

    Now if the user selects the value c in first drop down i must show only yes option in the second drop down.

    How can i do this?

    -Ballack.

  2. #2
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    Ballack,

    Try something like this on the Click event of the first ListBox. This should clear the second ListBox and then add back only "Yes.

    Please Login or Register  to view this content.
    I'm sure you will need to play around with this a little for it to fit into your application.

    Hope it helps!
    Sincerely,
    Jeff

  3. #3
    Registered User
    Join Date
    05-11-2007
    Posts
    93
    Thank you Jeff

  4. #4
    Registered User
    Join Date
    05-11-2007
    Posts
    93
    Hi Jeff,
    I dont use useforms, i write list data in some cells and define a name for it and then use it in LIst data. that is i go to data->validation
    and in settings i specify allow as "List" and source i specify as =name.

    So if i use this to specify the list box how can i make the listbox show only yes based on some condition?

  5. #5
    Registered User
    Join Date
    08-25-2006
    Posts
    30
    You could try playing with the Change event for the worksheet, putting in code that, when there's a change, checks what cell range the change is on. If it's one of the "name" list validation cells, then it calls a sub which rewrites the equivalent Yes / No validation cell to suit the selection. To be fair, if the only option is Yes, then it may be better to have the macro clear the Yes / No validation bit completely and just write "Yes" to the cell.

  6. #6
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    ballack,

    You can try something like this

    Please Login or Register  to view this content.
    In this code, it will check to see what the value is of E1. If the value is "c", it changes the drop down list in F1 to just Yes otherwise it changes it to Yes, No.

    This code would go under ThisWorkbook so that it would fire when any cell is changed. You will definitely have to recode to make this fit your application. I am not real familiar with this, so I cannot tell you if it is set up exactly right, but it does function in the fashion you have requested on my sample sheet.

    Hopefully, this will give you something to play around with and get you started.

+ 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