+ Reply to Thread
Results 1 to 8 of 8

VBA to expand a referenced range of cells

  1. #1
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    VBA to expand a referenced range of cells

    Hi all,

    Looking for some help with my code.

    Here is what I have:

    A combobox that references a range of cells and that launches another UserForm when "Other" is selected:

    Please Login or Register  to view this content.
    And a UserForm that adds another value to the combobox:

    Please Login or Register  to view this content.
    What I would like to happen is the following: When a value is added using the AddOtherValue UserForm it adds to the worksheet where the combobox is making the referenece (in addition to the combobox code that exists already). I would then like the range being referenced by cmboProjectType to expand by 1 (so that the next time this UserForm is launched it will show the new value that was added in the dropdown)

    The easiest way I see to accomplish this is to have the range reference a value (say A3) and to keep referencing values in that column until it reaches a blank.

    I am open to suggestions though!

    Thanks in advance,

    Wolf

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA to expand a referenced range of cells

    I would normally file a combobox in the Userform's Initialize event.

    This should give you an idea.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: VBA to expand a referenced range of cells

    Brilliant this is exactly what I needed! Now one other issue: I want to have the value "Other" at the bottom of the dropdown list. Could I add it like this?:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: VBA to expand a referenced range of cells

    Well clearly this code is wrong but you get the idea! Just want the value Other to always be at the bottom of the dropdown list...

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA to expand a referenced range of cells

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: VBA to expand a referenced range of cells

    Only thing I don't like about the .AddItem is that if you hit the dropdown a second time it adds the value again... But yeah this works. Thanks for the help!

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA to expand a referenced range of cells

    I would not fill it that way myself. Try using .clear to clear the entries?

    I guess one might also want to consider removing duplicates from such a list. IF you want that, reference this thread and ask for it in another thread.

  8. #8
    Registered User
    Join Date
    06-28-2013
    Location
    London, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: VBA to expand a referenced range of cells

    Quote Originally Posted by Kenneth Hobson View Post
    I would not fill it that way myself. Try using .clear to clear the entries?

    I guess one might also want to consider removing duplicates from such a list. IF you want that, reference this thread and ask for it in another thread.
    I think you mean...

    IF you want that THEN reference this thread haha

    End If

    Just trolling.

    Thanks again for the help!

+ 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