+ Reply to Thread
Results 1 to 5 of 5

Auto Editing the Row source.

  1. #1
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122

    Auto Editing the Row source.

    Hi,
    I have a combobox in the userform. And I have a data range: (A2:A40).

    I want the dropdown to read the range A2:A40.

    That will help the user choose from the dropown list.

    Now what if the range gets smaller or larger. Do I have to change the "Row Source" Everytime a change takes place?

    I mean A40 is the destination, but it might be less in the future so how do I
    fix: A2:A40 once and for all.


    Thanks,
    Nawaf

  2. #2
    Toppers
    Guest

    RE: Auto Editing the Row source.

    Hi,
    Try this:

    Private Sub UserForm_Initialize()
    lr = Cells(Rows.Count, "A").End(xlUp).Row ' Last row
    ComboBox1.RowSource = "a2:a" & lr
    End Sub

    HTH

    "countryfan_nt" wrote:

    >
    > Hi,
    > I have a combobox in the userform. And I have a data range: (A2:A40).
    >
    > I want the dropdown to read the range A2:A40.
    >
    > That will help the user choose from the dropown list.
    >
    > Now what if the range gets smaller or larger. Do I have to change the
    > "Row Source" Everytime a change takes place?
    >
    > I mean A40 is the destination, but it might be less in the future so
    > how do I
    > fix: A2:A40 once and for all.
    >
    >
    > Thanks,
    > Nawaf
    >
    >
    > --
    > countryfan_nt
    > ------------------------------------------------------------------------
    > countryfan_nt's Profile: http://www.excelforum.com/member.php...o&userid=11051
    > View this thread: http://www.excelforum.com/showthread...hreadid=386366
    >
    >


  3. #3
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122
    Thanks,

    But, When I run the code I get "Compile error: Varriable not defined". And "lr =" is highlighted. What Am I missing? Or what did I do wrong?

    Nawaf

  4. #4
    Toppers
    Guest

    Re: Auto Editing the Row source.

    Add "Dim lr as Long" to the macro as I take it you have (correctly) an
    "Option explicit" statement in you code.

    HTH

    "countryfan_nt" wrote:

    >
    > Thanks,
    >
    > But, When I run the code I get "Compile error: Varriable not defined".
    > And "lr =" is highlighted. What Am I missing? Or what did I do wrong?
    >
    > Nawaf
    >
    >
    > --
    > countryfan_nt
    > ------------------------------------------------------------------------
    > countryfan_nt's Profile: http://www.excelforum.com/member.php...o&userid=11051
    > View this thread: http://www.excelforum.com/showthread...hreadid=386366
    >
    >


  5. #5
    Forum Contributor
    Join Date
    06-24-2004
    MS-Off Ver
    Excel 2013 Pro Plus
    Posts
    122
    Ok 2 more questions:

    1: Do I need to specify the sheet name in the code because A2 is vague without mentioning the sheet name. The sheet name is "LookupLists".

    2: Where do I place the code. I mean should it be inside the comboBox "View Code"

+ 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