+ Reply to Thread
Results 1 to 11 of 11

Populate listbox in userform based on string

  1. #1
    Forum Contributor
    Join Date
    09-05-2007
    Posts
    148

    Populate listbox in userform based on string

    Hi

    I have a list of data say for example name, price and code.

    I want to create a userforms with three boxes where the user can enter either of the 3 above parameters.

    I then want a listbox to be populated with ALL of the results in my data sheet. I also need to columns headings in the list box.

    I'm having a bit of trouble finding the code for this.


    Could someone help me please?


    Thanks

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Populate listbox in userform based on string

    you can only have column headers in a listbox if you bind it to a worksheet range using the rowsource property, which you won't be able to do if you want to return only some records-unless you copy those records to a separate worksheet.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    09-05-2007
    Posts
    148

    Re: Populate listbox in userform based on string

    OK, even if headers are not availible, just getting the results would be useful.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Populate listbox in userform based on string

    a sample workbook would be helpful. you haven't provided any detail so far to indicate where any of the information is ;-)

  5. #5
    Forum Contributor
    Join Date
    09-05-2007
    Posts
    148

    Re: Populate listbox in userform based on string

    Sure thing, here you go.

    It's just a basic example but should illustrate what I need.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    09-05-2007
    Posts
    148

    Re: Populate listbox in userform based on string

    Please, anyone?

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Populate listbox in userform based on string

    here is a sample. I changed your forms listbox to an activex one since you want multiple columns and set all the controls to not move or size with cells because the code uses an autofilter. personally I would recommend using an actual userform or putting the controls onto a separate sheet for your actual workbook
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-05-2007
    Posts
    148

    Re: Populate listbox in userform based on string

    Awesome, great stuff, thanks!

    Yeah i'll def use a proper form in my final version.

    Is there no way I can have the column headings in the list? I've seen an example of this online but I have no idea how it's doing it as the code is very complex in comparison to your example.

    Please Login or Register  to view this content.

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Populate listbox in userform based on string

    if you want them in the list that's easy but if you want real column headers (ie they can't be selected) then you can only do that by copying the data somewhere else

  10. #10
    Forum Contributor
    Join Date
    09-05-2007
    Posts
    148

    Re: Populate listbox in userform based on string

    Yeah sorry, in the list is what I meant.

    Would you be able to ammend the sample you sent me please to include it?

    Thanks

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Populate listbox in userform based on string

    change the module1 code to
    Please Login or Register  to view this content.
    and I reckon that oughta do it

+ 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