Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Combining 2 arrays side-by-side

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Combining 2 arrays side-by-side

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" wrote in message
...
|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.
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Combining 2 arrays side-by-side

Or dump both arrays to a sheet and then make a new array from the combined
ranges.

RBS

"Bob" wrote in message
...
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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Combining 2 arrays side-by-side

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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Combining 2 arrays side-by-side

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.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Combining 2 arrays side-by-side

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Series display order sequential, not grouped side-by-side [email protected] Charts and Charting in Excel 2 November 21st 08 02:22 PM
combining stacked with side-by-side bar BorisS Charts and Charting in Excel 5 November 15th 07 09:20 PM
How2 setup one page distribution report side by side results sailorgirl Charts and Charting in Excel 0 August 20th 07 09:14 PM
Display columns side by Side in the Data Area of a Pivot table Sue Excel Discussion (Misc queries) 1 March 21st 06 02:12 AM
Data markers in a stacked chart will not sit side by side by month WCH CHART PERSON Charts and Charting in Excel 2 March 28th 05 04:31 PM


All times are GMT +1. The time now is 03:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"