+ Reply to Thread
Results 1 to 7 of 7

Code to create a new listbox on a userform

  1. #1
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Code to create a new listbox on a userform

    I have a existing UserForm. I need, in the UserForm_Initialize code to add any number of listboxes which I expect I could due with a loop.

    But, I can’t determine the code to create a new listbox.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Code to create a new listbox on a userform

    Something like this

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to create a new listbox on a userform

    Why do you need/want to add multiple listboxes at run time?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Re: Code to create a new listbox on a userform

    Thanks Andy, exactly what I needed.


    Norie,
    I need as many listboxes as a variable quantity the calculations determine.
    There might be 4 today and 20 tomorrow. There is no upper limit so I can't just have 20 listboxes and only show the ones I need. The user has to provide an input for each instance.

    Since the options are always the same, I could just have them select & submit multiple times off a single listbox, but that;s too much for the user to keep track of in his head.

    Additionally, there is sometimes a second option to choose so if the total is 5, there could be (5) listboxAoptions & 2 listboxBoptions. If the total is 20, there could be (20) listboxAoptions and (4) listboxBoptions, or 20 of each A & B.
    The user really needs to be able to see the whole picture, what he chose for each instance.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Code to create a new listbox on a userform

    I know Andy solved your problem but what if your UserForm has room for 30 and you'll need 35 listboxes?
    I had a similar thing but I added the maximum amount ever to be needed, hid them all and unhid the ones I did need.
    Just a thought.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to create a new listbox on a userform

    carsto

    I wasn't actually going to suggest adding multiple listboxes at design time etc.

  7. #7
    Forum Contributor
    Join Date
    08-14-2006
    Location
    USA
    MS-Off Ver
    2019
    Posts
    686

    Re: Code to create a new listbox on a userform

    jolivanes - There is no "maximum", the potential needed is unlimited

    Norie, I'm just trying to explain my thoughts to those so willing to help!


    I thought about adding another listbox when they filled out the first, and so on and so on because they don't actually have to choose options every time, they can use the program default selection but they must be able to change the default selection for any or all.

    The problem I'm running into is the value of all this isn't worth the time I'm spending on it. (Worth it to me as education, but not to my employer!)

+ 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] List of items in a userform listbox, object required error in code
    By jayherring86 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2015, 09:10 AM
  2. Changing listbox code to work in a userform
    By cosmicwinds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2014, 01:52 PM
  3. Transfer Data From One Userform Listbox to Another Userform Listbox with 11 columns
    By sparkoft in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-18-2013, 10:54 AM
  4. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM
  5. Listbox Help-create VBA code
    By lehainam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2005, 06:05 AM

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