PC Review


Reply
Thread Tools Rate Thread

Combining 2 arrays side-by-side

 
 
=?Utf-8?B?Qm9i?=
Guest
Posts: n/a
 
      10th Sep 2007
I have 2, two-dimensional Variant arrays. Both arrays have the same number
of "rows". However, each array has a different number of "columns".

Is it possible to combine both arrays in such a way that the 2nd array is
appended to the right (rather than to the bottom) of the 1st array?

I have looked at both Beban's and Pearson's excellent (and indispensable)
UDFs, but unless I'm missing something, none of the UDFs appear to accomplish
what I'm trying to do.

Any guidance in this area would be greatly appreciated. Thanks.

 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      10th Sep 2007
So if the first array was say 10 rows by 5 columns you'd want to start by
adding 2 columns if that's what the second had. So

ReDim Preserve FirstArray(1 to 10, 1 to 7) ''assume 1-based

Then write column 1 of SecondArray to column 6 and 2 to 7, which is easy,
right?

--
Jim
"Bob" <(E-Mail Removed)> wrote in message
news:AADB17ED-7CAE-43B5-AEE7-(E-Mail Removed)...
|I have 2, two-dimensional Variant arrays. Both arrays have the same number
| of "rows". However, each array has a different number of "columns".
|
| Is it possible to combine both arrays in such a way that the 2nd array is
| appended to the right (rather than to the bottom) of the 1st array?
|
| I have looked at both Beban's and Pearson's excellent (and indispensable)
| UDFs, but unless I'm missing something, none of the UDFs appear to
accomplish
| what I'm trying to do.
|
| Any guidance in this area would be greatly appreciated. Thanks.
|


 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      10th Sep 2007
Or dump both arrays to a sheet and then make a new array from the combined
ranges.

RBS

"Bob" <(E-Mail Removed)> wrote in message
news:AADB17ED-7CAE-43B5-AEE7-(E-Mail Removed)...
>I have 2, two-dimensional Variant arrays. Both arrays have the same number
> of "rows". However, each array has a different number of "columns".
>
> Is it possible to combine both arrays in such a way that the 2nd array is
> appended to the right (rather than to the bottom) of the 1st array?
>
> I have looked at both Beban's and Pearson's excellent (and indispensable)
> UDFs, but unless I'm missing something, none of the UDFs appear to
> accomplish
> what I'm trying to do.
>
> Any guidance in this area would be greatly appreciated. Thanks.
>


 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      10th Sep 2007
The array elements in the "rows" below the appended array will be blanks:

'Assign to a variable the number of "columns" in each array
ub12 = UBound(arr1, 2)

'Increase the number of "columns" of the larger array (arr1)
'to accommodate the appended array (arr2); this appends an
'array of blanks to the right of the larger array.
ResizeArray arr1, , 2 * ub12

'Replace the top portion of the array of blanks with the
'array to be appended
ReplaceSubArray arr1, arr2, 1, ub12 + 1

The ResizeArray line can be accomplished without resort to the
downloaded functions, since it's only the upper bound of the last
dimension that is being changed:

ReDim Preserve arr1(1 to UBound(arr1), 1 to 2 * ub12)

Whatever, once you've resized the first array, the ReplaceSubArray
function indeed accomplishes what you are trying to do; which, by the
way, can be accomplished simply by looping to add the array elements to
the first array. As with the functions generally, the ReplaceSubArray
function simply has the appropriate looping, and the starting points,
built into it.

Alan Beban

Bob wrote:
> I have 2, two-dimensional Variant arrays. Both arrays have the same number
> of "rows". However, each array has a different number of "columns".
>
> Is it possible to combine both arrays in such a way that the 2nd array is
> appended to the right (rather than to the bottom) of the 1st array?
>
> I have looked at both Beban's and Pearson's excellent (and indispensable)
> UDFs, but unless I'm missing something, none of the UDFs appear to accomplish
> what I'm trying to do.
>
> Any guidance in this area would be greatly appreciated. Thanks.
>

 
Reply With Quote
 
=?Utf-8?B?Qm9i?=
Guest
Posts: n/a
 
      11th Sep 2007
Alan,
Thanks for your help! I really appreciate it.
Although I'm still a novice when it comes to VBA, I have learned a lot from
you when it comes to manipulating arrays.
Thanks again,
Bob


"Alan Beban" wrote:

> The array elements in the "rows" below the appended array will be blanks:
>
> 'Assign to a variable the number of "columns" in each array
> ub12 = UBound(arr1, 2)
>
> 'Increase the number of "columns" of the larger array (arr1)
> 'to accommodate the appended array (arr2); this appends an
> 'array of blanks to the right of the larger array.
> ResizeArray arr1, , 2 * ub12
>
> 'Replace the top portion of the array of blanks with the
> 'array to be appended
> ReplaceSubArray arr1, arr2, 1, ub12 + 1
>
> The ResizeArray line can be accomplished without resort to the
> downloaded functions, since it's only the upper bound of the last
> dimension that is being changed:
>
> ReDim Preserve arr1(1 to UBound(arr1), 1 to 2 * ub12)
>
> Whatever, once you've resized the first array, the ReplaceSubArray
> function indeed accomplishes what you are trying to do; which, by the
> way, can be accomplished simply by looping to add the array elements to
> the first array. As with the functions generally, the ReplaceSubArray
> function simply has the appropriate looping, and the starting points,
> built into it.
>
> Alan Beban
>
> Bob wrote:
> > I have 2, two-dimensional Variant arrays. Both arrays have the same number
> > of "rows". However, each array has a different number of "columns".
> >
> > Is it possible to combine both arrays in such a way that the 2nd array is
> > appended to the right (rather than to the bottom) of the 1st array?
> >
> > I have looked at both Beban's and Pearson's excellent (and indispensable)
> > UDFs, but unless I'm missing something, none of the UDFs appear to accomplish
> > what I'm trying to do.
> >
> > Any guidance in this area would be greatly appreciated. Thanks.
> >

>

 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      11th Sep 2007
Bob wrote:
> Alan,
> Thanks for your help! I really appreciate it.
> Although I'm still a novice when it comes to VBA, I have learned a lot from
> you when it comes to manipulating arrays.
> Thanks again,
> Bob
>


You're welcome. I should have mentioned that the code works only on
1-based arrays. It needs to be modified to generalize it.

Alan Beban
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
combining stacked with side-by-side bar =?Utf-8?B?Qm9yaXNT?= Microsoft Excel Charting 5 15th Nov 2007 09:20 PM
Re: Combining two stacked column chart side by side Rock Windows XP General 0 17th Jan 2007 12:42 AM
Re: Combining two stacked column chart side by side Pegasus \(MVP\) Windows XP General 0 16th Jan 2007 10:29 PM
Combining multiple queries (on a single table), so the results appear side by side? Mike Microsoft Access Queries 7 9th Nov 2004 04:27 AM
Using Side-by-Side Calendars, would like side-by-side DAYS Matt Landis Microsoft Outlook Calendar 6 19th Mar 2004 09:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:32 PM.