Consulting

Results 1 to 7 of 7

Thread: Solved: Combining Dynamic Ranges

  1. #1
    VBAX Regular
    Joined
    May 2011
    Posts
    46
    Location

    Solved: Combining Dynamic Ranges

    Hello,

    To fill a combobox I use the following formula as dynamic range.
    Is it possible however to add a second dynamic range to it?


    [VBA]
    =OFFSET(Strt!$I$5;0;0;COUNTA(Strt!$I:$I);1)
    =OFFSET(Strt!$L$5;0;0;COUNTA(Strt!$L:$L);1)[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is your code to add it, do you set the List property or RowSource?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    May 2011
    Posts
    46
    Location
    Hello xld,

    I use it as a named range and place it in RowSource

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    As I feared.

    If you do want to use this method, you could create a function that builds an array from both, like so

    [vba]

    Function fxUnion(ParamArray rng()) As Variant
    Dim ary As Variant
    Dim cell As Range
    Dim cnt As Long
    Dim i As Long
    ReDim ary(1 To 1)
    For i = LBound(rng) To UBound(rng)

    For Each cell In rng(i)

    cnt = cnt + 1
    ReDim Preserve ary(1 To cnt)
    ary(cnt) = cell.Text
    Next cell
    Next i
    fxUnion = ary
    End Function[/vba]
    and load the combo in the Initialise of the form

    [vba] Me.ComboBox1.List = fxUnion(Range("_rng1"), Range("_rng2"))
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    May 2011
    Posts
    46
    Location
    Awesome xld, it works great!

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    BTW, that function allows for any number of ranges to be passed to it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    May 2011
    Posts
    46
    Location
    Quote Originally Posted by xld
    BTW, that function allows for any number of ranges to be passed to it.
    Great! thanks again for your help

Posting Permissions

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