+ Reply to Thread
Results 1 to 18 of 18

How to have a userform list box fill automaytically with cell values

  1. #1
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    How to have a userform list box fill automaytically with cell values

    I have a userform that I would like to auto populate a list box. The value's I want to populate this with are in Sheet3 cells R4:R300. But what I need to do is look at column T and if any value in column T is 12 then the value in column R is what will fill this list box. There could be up to 30 items that would be in this list box. List box is called ListBox 1

    Thanks in advance
    Excel 2010

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,336

    Re: How to have a userform list box fill automaytically with cell values

    Hi Zimmerman...

    You should update your profile to say either Excel 2003 or 2010 or both....

    Here is an example that should get close to what you are asking.

    I've created a Userform that has a single listbox in it. The ListBox.RowSource is what you need to change. I've done some Dynamic Named Ranges to keep it easier. You find the ListBox properties by clicking on the ListBox and showing (view) Properties.

    If you look at the code behind the Userform, I've added some code to check the RList to see if it has a 12 in it. If it does I show a different RowSource.

    I hope this example gets you closer to solving your problem. Lots to learn here if it doesn't make sense.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    That seems to work out perfect. Only issue that I'm having is I have this code in it. So when I change sheets to go to sheet 3 it gives me an error that says row source is out of range. Any ideas on what I can do?

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    By the way. what you did was impressive

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to have a userform list box fill automaytically with cell values

    RowSource isn't supported by my Mac, so I came up with this.
    Note that the second (hidden) column of the list box retains the address of the cell from which the list item came.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,336

    Re: How to have a userform list box fill automaytically with cell values

    What happens if you remove the "vbModeless" ? Does it work then?

    Did you see and copy the Dynamic Named Ranges to your working version?

  7. #7
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    Sorry for the delay. It was getting late last night. Here's what I have right now. And when I change to sheet 3 the userform with the list box show up like it's supposed to and whne I change to another sheet it goes away like it's supposed to. Now my problem is the list box is pulling every cell value in column R. It's not recognizing if there's a 12 in column T to only pull that value in column R.


    Please Login or Register  to view this content.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to have a userform list box fill automaytically with cell values

    Can you attach a sample workbook of your situation?
    The code explicitly asks that column T be 12 before adding any item to the ListBox.
    I suspect that the cell locations need to be checked.
    Also, my code assumes that these 12's are constants and not the result of a formula evaluation.

    Finally, the code
    Please Login or Register  to view this content.
    was placed as a demonstration of how to retrieve the selected item's source cell address. It is not necessary and it does not go in the Userform_Intialize event, but in the ListBox1_Change event.

  9. #9
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    Sorry for asking this but how do I attach the file?

  10. #10
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    Yes the result in column T is a formula. It's subtracting years. If I could attach my fie you'd probably see an easier way to accomplish what I'm trying to do.

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to have a userform list box fill automaytically with cell values

    Try this
    Please Login or Register  to view this content.
    But if you are going to different sheets, hiding the user form, changing cells which change column T and going back to look at the user form, that code should be moved to the Activate event rather than the Intialize event.

  12. #12
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    That seemed to work Thank you very much. One more question though if you don't mind. This workbook is for a little league baseball draft. This list shows all the available 12 year olds. If a 12 year old gets moved from the list to a team is there a way to have this userform update and now that kid will be removed from the listbox on the userform.

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to have a userform list box fill automaytically with cell values

    Yes there is a way,
    Please Login or Register  to view this content.
    But when to trigger that line would depend on how Janet gets "chosen"

  14. #14
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    Ideally it would be nice to have the user pick the name from the list. Like click on the name and drag it over to whatever team picked them.

  15. #15
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to have a userform list box fill automaytically with cell values

    This might give you some ideas.
    Select a player from the list box and drag the box to the team of your choice.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    ok that's awesome. I'll play around with this. But this is great

  17. #17
    Forum Contributor
    Join Date
    07-01-2010
    Location
    Niles, Michigan
    MS-Off Ver
    Excel 2010
    Posts
    137

    Re: How to have a userform list box fill automaytically with cell values

    Question for you though. Can I drag names from the list n the userform to cells in a worksheet rather than dragging names from the userform to another listbox on that same userform like you have? As it stands right now on yours you can drag names over to a team that's listed on the userform. I would love to have my userform show the list of kids when that sheet is active (as it does now) but then the user can pick from that userform list and drag that name to a cell on the sheet

  18. #18
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to have a userform list box fill automaytically with cell values

    You are working with a modeless user form that my Mac won't support.
    My guess is: No, you can't drag it to the worksheet, but you could set a control to automatically reflect its changes in a worksheet.

    What I posted in Post#15 uses Labels to accept the player's names (I started with ListBoxes but discovered that they are always in front which gave a bad visual effect, so changed to Labels.)

    It should be easy enough to change that to TextBoxes holding the team rosters and those text boxes being linked to cells.

    Something like

    Please Login or Register  to view this content.
    Perhaps also paired with a Worksheet_Change event to fill the TextBox when the cells in the worksheet are changed.
    As i said, I can't test a modeless user form.

+ 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. List/Fill Numbers Between Two Values
    By jevi05 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-31-2015, 07:05 AM
  2. [SOLVED] userform combobox2 does not have unique values and will not fill listbox
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2013, 12:22 PM
  3. Copy or Cut userform text/list box values to a worksheet cell for printing
    By sumitos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2013, 05:38 AM
  4. Auto fill values based on drop down list
    By Jahoobie in forum Excel General
    Replies: 2
    Last Post: 09-21-2010, 11:04 AM
  5. using a userform listbox to fill numbers in a cell
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-22-2010, 01:56 AM
  6. To Fill Values Right or Down in a List in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 10-31-2007, 05:18 AM
  7. Userform to enter values and shown in same userform in list
    By helmekki in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2005, 11:23 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