+ Reply to Thread
Results 1 to 22 of 22

Combo box row source in an userform

  1. #1
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Combo box row source in an userform

    In an userform I have a combobox "STR1" for which I try to set the list source.....
    The list will depend on another combobox "FLD", but the list will be generated from the worksheet "RECAP" range already named "month" (a2:a142).

    I don't manage to refer to the worksheet range....

    here below my code

    [CODE]
    With STR1
    If FLD.Value = "MONTH" Then
    .additem = "'RECAP'!A2:A142"
    end with
    [CODE]

    Moreover although I want to be able to pick a value from the list in the combobox STR1, I want also to be able to type any value even if not in the list....

    many thanks in advance.
    Last edited by mariec_06; 06-10-2016 at 04:27 AM.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Try:
    Please Login or Register  to view this content.
    Or:
    Please Login or Register  to view this content.
    BSB

  3. #3
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    wouah works perfect, I though I had to do this under userform initialized

    if the rowsource is not named but it's for example column "AG" of worksheet "recap"....how should I put it?

  4. #4
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    My columns in each worksheet have headers ....if it can help

  5. #5
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Do you mean you want to refer to a range of cells in column AG specifically or are you trying to make the rowsource dynamic based on the value in the other combobox?

    BSB

  6. #6
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    Hum what I am trying trying to make the rowsource dynamic based on the value in the other combobox, considering that the box "FLD" change

    so

    If FLD=month then STR1.rowsource = worksheets ("recap"). column A
    if FLD= "invoicing quantity (p)" then STR1.rowsource = worksheets ("pricing final"). column M

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Why not give the ranges names and refer to them in the code?
    If it's because the ranges could vary in size as data is added/removed, you could make the named ranges dynamic so they resize automatically.

    BSB

  8. #8
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    each worksheet (which are repeating some info one from the other) are all preformatted and the range to consider are always row2:row142 (although until now only the row 2 to 31 are filled in but new records are added regularly but my range is 2:142)

    my problem in VBA is that I never know how to refer to a column or a row in a worksheet (I never study VBA) and plus as per what I saw when defining a rowsource the way to refer to worksheet is different....

    for the moment I can not name each range that's why I would need to define the column by the worksheet name and the column number or letter...

    I tried rowsource = "'RECAP'!A2:A142" but it obviously does not work

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Combo box row source in an userform

    Never use AddItem or Rowsource to fill a Combobox, use the List method instead.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  10. #10
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Quote Originally Posted by mariec_06 View Post
    I tried rowsource = "'RECAP'!A2:A142" but it obviously does not work
    That approach works here in the attached.

    BSB
    Attached Files Attached Files

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Quote Originally Posted by bakerman2 View Post
    Never use AddItem or Rowsource to fill a Combobox, use the List method instead.
    Perhaps an explanation of why to use List over the other methods would be helpful.

    BSB

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Combo box row source in an userform

    1. AddItem ==> reading line by line is never a good idea (slow, too much Sheet interaction)
    2. RowSource ==> fixed range to be decided in advance.
    3. List ==> much more flexible because you can use SpecialCells, Currentregion, Resize, End(xlUp), etc. to read in dynamic range in one go.

  13. #13
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    I tried
    Please Login or Register  to view this content.
    it does not work, I got an "invalid property value"

  14. #14
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    I think to diagnose that we will need to see the workbook. Could you attach it?

    BSB

  15. #15
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    apparently it could be because I renamed my combobox.....

  16. #16
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Quote Originally Posted by mariec_06 View Post
    apparently it could be because I renamed my combobox.....
    Hahaha, that'll do it!

    BSB

  17. #17
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    Here attached the file, the userform is the "test" one (don't look at the rest of the code I am working on it), the issue is for the moment under "Fld_afterupdate"
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    here attached the file, the userform is "test" one and the issue is under FLD_afterupdate (don't look at the rest of the code I am working on it)
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    SOLUTION FOUND

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    Don't know what was wrong but now it works

    thanks to all

  21. #21
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Combo box row source in an userform

    Glad you've got your solution

    BSB

  22. #22
    Forum Contributor
    Join Date
    10-07-2015
    Location
    cyprus
    MS-Off Ver
    Microsoft 365
    Posts
    182

    Re: Combo box row source in an userform

    Well actually it works good but it does not allow me to enter any value if not in the source.....

    I would like to be able to pick a value from the row source or to type any value I want....

    Moreover I have an issue when it concerns dates....like if FLD= "B/L date", I would like to be able to type any date value or to pick one of the existing one.........Another issue is that I don't know in the code, where to set the format of the boxes.......

    Here attached the working file ( the filter works only on the first worksheet for the moment) but it can be useful to some maybe
    Attached Files Attached Files

+ 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. VBA Userform combo box - need to enable user to add new item if not listed in combo box
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2015, 07:25 PM
  2. [SOLVED] How to reference a second Combo box’s output based on previous Combo Box’s Row source
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2012, 11:27 AM
  3. [SOLVED] Dynamic Row source for Combo box on Userform.
    By excelkeechak in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2012, 09:58 PM
  4. Combo Box Userform To Open 2nd Combo Box
    By WPJensen in forum Excel General
    Replies: 8
    Last Post: 03-10-2011, 06:33 AM
  5. Dynamic combo row source - works only if active source worksheet
    By fredpox in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-21-2010, 07:16 AM
  6. 6 Character limit on userform combo box source?
    By kanuvas in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-22-2008, 06:59 AM
  7. Combo-box Source a single row
    By routeram in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2005, 12:01 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