+ Reply to Thread
Results 1 to 5 of 5

Use RowSource in ComboBox

  1. #1
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    289

    Use RowSource in ComboBox

    I see a lot of advice online not to use RowSource in a Userform ComboBox, but rather build the list in the code, but no explanation of why.

    My list is 84 lines long and from a named range. It is the first column in my database and will never grow beyond 84 rows. Is that something I should be concerned about as I stumble along in this project?

    Thanks

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

    Re: Use RowSource in ComboBox

    Quote Originally Posted by Len Silva View Post
    I see a lot of advice online not to use RowSource in a Userform ComboBox, but rather build the list in the code, but no explanation of why.

    My list is 84 lines long and from a named range. It is the first column in my database and will never grow beyond 84 rows. Is that something I should be concerned about as I stumble along in this project?

    Thanks
    People overstate things sometimes. Either method is fine but there are differences in what you can and cannot do with each.

    With the .RowSource method, you are limited in Adding\Removing\Editing the list. To edit the list, you would have to edit the values on the sheet. Then the list would automatically update with what is on the sheet. You couldn't add\remove\edit the list directly without changing the sheet. Also, the RowSource has to be one contiguous range.

    The .List method allows for much more flexibility in directly manipulating the list and isn't directly tied to any one range on the sheet.

    The RowSorce method is perfectly fine to use if you want to have a fix list directly linked to one contiguous range on the sheet. Which method to use just depends on your requirements.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use RowSource in ComboBox

    I have personally never had a problem with using RowSource in a situation like yours.

    However, instead of assuming that something will NEVER change, try to build flexibility into your overall approach, to allow things to change without needing a major re-write.

    Dynamic named ranges:
    So, for example, instead of having static named ranges, create dynamic ones. This way if 84 rows becomes 83 or 85, it will still work.

    With header in cell A1, the data starting in A2 and there being no empty cells within column A until you get to the end of the data,
    use this as your named range RefersTo formula:
    =OFFSET(mySheetName!$A$1,1,0,COUNTA(mySheetName!$A:$A)-1,1)
    (simply amend mySheetName to match your own)

    In the attached workbook this formula (which counts the number of non-empty cells in the named range ) is in cell B1:
    =COUNTA(myName)
    Add a few values immediately below A84, and then check the value of B1
    Attached Files Attached Files
    Last edited by kev_; 06-11-2017 at 03:24 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    289

    Re: Use RowSource in ComboBox

    Thank you both, that answers my question very well. In this case, the list is absolutely limited and will never change (the number of units in my condo).

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use RowSource in ComboBox

    You are welcome, thank for the reps

+ 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. [SOLVED] Userform combobox to populate RowSource for new values in combobox
    By Stratfordoaks in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 12-17-2013, 01:18 PM
  2. [SOLVED] Combobox value defines Combobox Rowsource
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-03-2013, 08:57 AM
  3. [SOLVED] Add RowSource to Userform ComboBox based on value on Another ComboBox
    By Baziwan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-10-2012, 01:17 PM
  4. Way to populate combobox rowsource based on previous combobox value
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-08-2012, 12:50 AM
  5. Combobox: How to determine the location of the selected item if combobox has rowsource
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2012, 03:24 PM
  6. Combobox rowsource
    By mike0123m in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2009, 02:46 PM
  7. Combobox rowsource
    By Marinos Andreou in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2006, 01:10 PM
  8. combobox rowsource as code
    By JasonSelf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-13-2005, 04:05 PM

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