Hi gurus,
Happy Friday!
I am trying to find a quick to read a non-contiguous range into a 2D array without iterating over every element.
Basically I'm trying to dump each area of the range into each column of the array without iterating over every element for the sake of performance.
I was trying an approach similar to below (which is syntactically incorrect) but was wondering if an approach like below is even possible?
The resulting array will ultimately be used to populate a multi-column combobox that I'm writing an autocomplete/search-as-you-type function for.
Code below is untested I just wrote it off the top of my head in code tags.
Happy Friday!
I am trying to find a quick to read a non-contiguous range into a 2D array without iterating over every element.
Basically I'm trying to dump each area of the range into each column of the array without iterating over every element for the sake of performance.
I was trying an approach similar to below (which is syntactically incorrect) but was wondering if an approach like below is even possible?
The resulting array will ultimately be used to populate a multi-column combobox that I'm writing an autocomplete/search-as-you-type function for.
Code below is untested I just wrote it off the top of my head in code tags.
VBA Code:
dim h as long, w as long, l as long
dim rSomeUnion as range, rArea as range
dim arrOut as Variant
set rSomeUnion = application.union( _
sheet1.range("a1:a200"), _
sheet1.range("c1:c150"), _
sheet1.range("e1:e100"), _
sheet1.range("g1:g250"))
'determine array dimensions
w = rSomeUnion.areas.count 'array width
for l = 1 to rSomeUnion.areas.count
h = iif(rSomeUnion.areas(l).rows.count > h, rSomeUnion.areas(l).rows.count, h) 'array max height
next l
'populate -- here is where i don't know the correct syntax?
'basically i'm trying to read each area of the union into each array column in a single statement. Not sure if this is possible?
redim arrOut(h, w)
for l = 1 to w
arrOut(1 to rSomeUnion.areas(l).rows.count, l) = rSomeUnion.areas(l).value2
next l