Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Series display order sequential, not grouped side-by-side | Charts and Charting in Excel | |||
combining stacked with side-by-side bar | Charts and Charting in Excel | |||
How2 setup one page distribution report side by side results | Charts and Charting in Excel | |||
Display columns side by Side in the Data Area of a Pivot table | Excel Discussion (Misc queries) | |||
Data markers in a stacked chart will not sit side by side by month | Charts and Charting in Excel |