+ Reply to Thread
Results 1 to 5 of 5

Listbox adjusting amount of elements and removing empty choices

  1. #1
    Forum Contributor
    Join Date
    07-13-2015
    Location
    Quebec, Canada
    MS-Off Ver
    2013
    Posts
    232

    Listbox adjusting amount of elements and removing empty choices

    Hi,

    I have a little issue with Listboxes. Here is my situation.

    I have a listbox with choices that are not always the same. What I mean by that is that if you, for example, change your choice in another listbox, the choices will change.

    (the excel file I added has an example)

    Depending on what you choose in the first listbox, the second one will have a different amount of choices aswell. I want the second listbox to show the correct choices, without empty spaces, and with the correct size.

    I'm using regular listboxes, so I'm not in a userform.

    What macro (because I guess I'll have to use a macro) should I put on the first listbox that will automatically adapt my second listbox accordingly?

    Refering to this file:
    listbox issue.xlsb

    You can try changing the first listbox and see what happens.
    I created 3 different listboxes that each show what the unique listbox should be showing.

    Thank you!

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Listbox adjusting amount of elements and removing empty choices

    Hi Jdevil,

    Each time 'Drop Down 2' changes value the value in cell 'L132' changes. We can take advantage of that in the Worksheet_Calculate() routine. The Worksheet_Change() routine does not get triggered because the value in 'L132' is changed by the ListBox and not changed manually.

    Try the following code in the Sheet Module:
    Please Login or Register  to view this content.
    This is a simple solution using the data you provided in your sample workbook. If your needs are more complicated, upload another sample workbook, and we can show you what to do if you need additional help.

    Lewis

  3. #3
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Listbox adjusting amount of elements and removing empty choices

    I'm not entirely sure what you want but took a guess.

    I used the ranges where you have labelled it should look like this and produced a single range that changes with the choices made in the boxes that I have surrounded with a heavy border. The Yellow area is the result. This list can be assigned to a listbox.

    This is the formula that I used to create the variable display in the yellow area. It is dependant upon the choices that you make.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  4. #4
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Listbox adjusting amount of elements and removing empty choices

    Here is another version of your file that has the yellow list attached to the listbox and also with a Data Validation drop down listing that dynamically changes with the number of values in the yellow area.

    I hope that some of this helps.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-13-2015
    Location
    Quebec, Canada
    MS-Off Ver
    2013
    Posts
    232

    Re: Listbox adjusting amount of elements and removing empty choices

    Quote Originally Posted by LJMetzger View Post
    Hi Jdevil,

    Each time 'Drop Down 2' changes value the value in cell 'L132' changes. We can take advantage of that in the Worksheet_Calculate() routine. The Worksheet_Change() routine does not get triggered because the value in 'L132' is changed by the ListBox and not changed manually.

    Try the following code in the Sheet Module:
    Please Login or Register  to view this content.
    This is a simple solution using the data you provided in your sample workbook. If your needs are more complicated, upload another sample workbook, and we can show you what to do if you need additional help.

    Lewis
    I was going for something similar, but using worksheet calculate on that worksheet makes it trigger too often and it made everything slow or sometime my excel crashed aswell

    I don't have much time right now to analyze it so I'll work on it later or tomorrow and see if I could do something with that or newdoverman's options

    I'll come back whenever I worked on it, thanks!

+ 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] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  2. [SOLVED] Trying to move listbox choices to individual cells
    By eculver in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2014, 09:48 AM
  3. [SOLVED] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  4. Getting the non empty elements from an array
    By kate.middleton1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2013, 12:53 PM
  5. [SOLVED] Automatically Update Drop Down List To Show Exact Amount Of Choices
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2012, 09:25 AM
  6. Removing array elements
    By panthers7171 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2009, 10:26 AM
  7. how to empty all elements in an array
    By exceltools2 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-12-2008, 12:54 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