Consulting

Results 1 to 5 of 5

Thread: Solved: Changing Range in comboBox

  1. #1

    Solved: Changing Range in comboBox

    Does anyone know how to limit the number of items in my list to show in my combo box. Right now I have specified the range for my list

    e.g A1:A30

    When I select from the list, the combo box displays all items from A1:A30 including those rows that are blank. Over time the user will enter more items into the combobox and when it is saved it will populate the range.

    However, this range might go beyond 30 items and I would like the combo box to only display the items in the list. If there are 5 items then display 5 items. If there are 100 items then display 100 items.

    What I'm really getting at is that I don't want to have to mess about with increasing ranges everytime I add or delete a new item to the list. Can this be done automatically?

    Thanks

    Ian

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    If its a combobox on a userform its the ListRows property. If its a combobox on a sheet, right click on it and click format control....then click the control tab and set the number of rows in the drop down lines box.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    You can create a named range which is dynamic and use that named range as your row source...

    [vba]
    =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A1:$A1000),1)
    [/vba]

    would refer to a range beginning in Sheet1 A1 and in this case, max of 1000 rows. The CountA function counts how many are occupied (i.e. not blank) and if your row source is linked to that named range, it would only contain as many items as are in your list.

    Hope that helps.
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




  4. #4
    The dynamic range works very well once I figured out that all external sheet ranges need to be named.

    Thanks

    Ian

  5. #5
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    I should have told you that..didn't know the ranges were on external files...

    Just be sure to mark thread solved and rate it if appropriate!
    If you have posted the same question at multiple forums, please read this IMPORTANT INFO.

    Please use the thread tools to mark your thread Solved


    Please review the Knowledge Base
    for samples and solutions , or to submit your own!




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •