LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to combine arrays?

This probably doesn't apply to your situation, but **IF** your A1, A2 and
Result arrays are **ALL** declared as being String arrays, you can perform
the combining of them in a single line of code...

Result = Split(Join(A1, Chr(1)) & Chr(1) & Join(A2, Chr(1)), Chr(1))

The resulting Result array will always be zero-based no matter what your
Option Base setting is (the Split function always produces zero-based
arrays). But remember, the above single line of code applies only if the
arrays are declared as Strings. For example...

Sub Test
Dim A1() As String
Dim A2() As String
Dim Result() As String
A1 = Split("1 2 3")
A2 = Split("4 5 6 7 8")
Result = Split(Join(A1, Chr(1)) & Chr(1) & Join(A2, Chr(1)), Chr(1))
Debug.Print UBound(Result)
End Sub

Note that in use, the elements of Result can still be used in calculations
as VB's behind-the-scenes automatic coercion would turn the numerical String
values into real numbers in order to perform the calculations.

--
Rick (MVP - Excel)


"Georg" wrote in message
...
How do I combine two one-dimensional arrays to one new one-dimensional
array?
E.g. if A1 is one-dimensional (3, 12, 8) and A2 is one-dimensional (6, 1,
0,
9) I want the resulting array to be (3, 12, 8, 6, 1, 0, 9). Thanks for
help!
Georg




 
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
Combine Two Arrays Into One. Tough. ryguy7272 Excel Worksheet Functions 4 May 8th 23 11:45 AM
Combine Two Similar Arrays Rob Excel Worksheet Functions 1 November 17th 09 09:31 PM
Function To Combine two 3-D arrays Darren Hill Excel Programming 2 December 30th 07 01:53 AM
Trouble with arrays (transferring values between two arrays) Keith R[_2_] Excel Programming 4 November 14th 07 12:00 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM


All times are GMT +1. The time now is 11:00 PM.

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

About Us

"It's about Microsoft Excel"