+ Reply to Thread
Results 1 to 4 of 4

dynamic listbox -- manually change .ListCount property

  1. #1
    Registered User
    Join Date
    12-14-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    5

    dynamic listbox -- manually change .ListCount property

    I have a feeling this is absurdly simple

    I have a listbox with a dynamic named range (created with OFFSET) in the ListFillRange. It appears to be the case that when the number of items in the ListFillRange increases, the .ListCount increases to account for it. But when the number of items decreases, the .ListCount doesn't come back down, leading to a box with blank rows at the end and (worse) errors in some of my code if one of those entries is selected.

    I have the number of items in the list (the length of the OFFSET) and I'd just like to add a line of code to my ListBox_Change event. Something like:

    Please Login or Register  to view this content.
    But VB doesn't seem to like it and I'm now wondering if I have to populate the list manually, etc. etc. I'd rather not just because I'm a VBA beginner and something that ought to take 10 minutes will take 3 hours. Is there any version of the above code that can do the job?

    Thanks!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: dynamic listbox -- manually change .ListCount property

    The ListCount property is read-only. It's not a property you can set. I don't think this is the problem. It's only a symptom.

    Can you post all the ListBox_Change procedure code?

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: dynamic listbox -- manually change .ListCount property

    FWIW I would recommend you populate the list in code rather than use the listfillrange anyway. It gives you much better control and you are less likely to find your listbox events being triggered unexpectedly.
    I agree completely with AlphaFrog though as regards the issue.
    Remember what the dormouse said
    Feed your head

  4. #4
    Registered User
    Join Date
    12-14-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: dynamic listbox -- manually change .ListCount property

    Thanks to you both. It's probably the right thing to do just to populate the listbox with code. I'll bug you again if I run into problems doing it that way!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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