+ Reply to Thread
Results 1 to 20 of 20

Filling a list box with a dynamic named range

  1. #1
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Filling a list box with a dynamic named range

    Hello guys!

    I'm having problems with this: I need to fill a list box (from the controls toolbox) when a command button is clicked with a named range from another sheet, this range is dynamic. For some reason, none of the codes I've tried are working! Is there any short straighforward piece of VB code I can use to do this??

    My dynamic named range is defined by
    Please Login or Register  to view this content.
    And I intend to copy the VB code into my sheet under

    Please Login or Register  to view this content.
    That's all, thank you!
    Last edited by Alicita; 02-01-2011 at 04:10 PM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Hi Alicita

    Is the ListBox on a UserForm?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    Hi!

    No, it's in the worksheet

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Hi Alicita

    Probably something like this
    Please Login or Register  to view this content.
    where "Stuff" is the name of your named range.

  5. #5
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    I tried it, but an error prompts: Run time error 438, object doesn't support this property or method

    ?

  6. #6
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Filling a list box with a dynamic named range

    Add this code to your Workbook and name your range "lbxlist"

    Please Login or Register  to view this content.

    see example
    A listbox on Sheet1 filled with list of names in Column B on Sheet2
    Attached Files Attached Files
    Last edited by jwright650; 02-01-2011 at 02:16 PM.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Filling a list box with a dynamic named range

    Please Login or Register  to view this content.
    VBA is better in creating dynamic ranges than Excel's formulae.

    Avoid using additem to populate a combobox/Listbox with multiple items (it isn't designed for this purpose, and it is extremely slow). List is especially designed for this task (see VBEditor's help).
    Last edited by snb; 02-01-2011 at 02:26 PM.



  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Hi Alicita

    Is the ListBox a Forms Control ListBox or an Activex Controls ListBox?

  9. #9
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    Now I'm getting "could not set the listcursor property. Not enough storage is available to complete this operation"

    It's from ActiveX controls ListBox

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Filling a list box with a dynamic named range

    Please post your workbook.

  11. #11
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Filling a list box with a dynamic named range

    Does my example run Ok for you?...or is that where you are getting the error message?

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Hi Alicita

    Works for me...see attached.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    @jwright650 : Your code did populate the list but It doesn't refresh it, I have to change of worksheets and then It shows refreshed, thanks anyway I feel I'm closer to the answer
    @snb: I'll post it later thanks
    @jaslake : Your code isn't working thanks anyway!

  14. #14
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    @jaslake: your code is working now! It was my mistake, but the problem is that it doesn't refresh*, how can I do that?

    * I want it to refresh everytime I click the command button (the source list changes, since is dynamic)
    Last edited by Alicita; 02-01-2011 at 02:44 PM.

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Try this
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    double post~
    Last edited by Alicita; 02-01-2011 at 03:49 PM.

  17. #17
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    It isn't refreshing

    weird thing is, that everytime I change of tab (worksheet) and come back to my sheet with my listbox, It's refreshed :S

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Hi Alicita

    How is the Dynamic Named Range getting changed? What's the process and how and where in the process does it get changed?

    We may need a copy of your workbook to fully understand what you're doing.

  19. #19
    Registered User
    Join Date
    01-09-2011
    Location
    Santiago, Chile
    MS-Off Ver
    Excel 2003
    Posts
    51

    Re: Filling a list box with a dynamic named range

    Problem Solved!

    It was a problem with Application.ScreenUpdating now Is good THANK YOU!!

  20. #20
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filling a list box with a dynamic named range

    Good detective work. Glad you got it working.

+ 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