Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Funciton that Combines 3 or more Arrays

Came across this function to combine arrays in this newsgroup (Sorry can't
rememer who posted it). It takes two arrays as arguments and returns 1
combined array. Works very well. Does anyone know if there is similar
function around for 3 or more arrays. I was going build in the third array
but realised I may need more than 3. Thanks and sorry for not crediting the
author of the function.


Function ArrayUnion(ByVal va1 As Variant, ByVal va2 As Variant) As Variant
Dim i As Long, Upper As Long
If TypeName(va1) = "Empty" Then
va1 = va2
Else
Upper = UBound(va1)
If LBound(va2) = 0 Then Upper = Upper + 1
ReDim Preserve va1(LBound(va1) To UBound(va1) + UBound(va2) -
LBound(va2) + 1)
For i = LBound(va2) To UBound(va2)
va1(Upper + i) = va2(i)
Next i
End If
ArrayUnion = va1
End Function

Thanks

EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Funciton that Combines 3 or more Arrays

Can't you just call the function twice like this:

ThreeArrays = ArrayUnion(ArrayUnion(Array1, Array2), Array3)

"ExcelMonkey" wrote:

Came across this function to combine arrays in this newsgroup (Sorry can't
rememer who posted it). It takes two arrays as arguments and returns 1
combined array. Works very well. Does anyone know if there is similar
function around for 3 or more arrays. I was going build in the third array
but realised I may need more than 3. Thanks and sorry for not crediting the
author of the function.


Function ArrayUnion(ByVal va1 As Variant, ByVal va2 As Variant) As Variant
Dim i As Long, Upper As Long
If TypeName(va1) = "Empty" Then
va1 = va2
Else
Upper = UBound(va1)
If LBound(va2) = 0 Then Upper = Upper + 1
ReDim Preserve va1(LBound(va1) To UBound(va1) + UBound(va2) -
LBound(va2) + 1)
For i = LBound(va2) To UBound(va2)
va1(Upper + i) = va2(i)
Next i
End If
ArrayUnion = va1
End Function

Thanks

EM

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Funciton that Combines 3 or more Arrays

Thats worth looking into. Hadn't thought of that. Thanks

"Charlie" wrote:

Can't you just call the function twice like this:

ThreeArrays = ArrayUnion(ArrayUnion(Array1, Array2), Array3)

"ExcelMonkey" wrote:

Came across this function to combine arrays in this newsgroup (Sorry can't
rememer who posted it). It takes two arrays as arguments and returns 1
combined array. Works very well. Does anyone know if there is similar
function around for 3 or more arrays. I was going build in the third array
but realised I may need more than 3. Thanks and sorry for not crediting the
author of the function.


Function ArrayUnion(ByVal va1 As Variant, ByVal va2 As Variant) As Variant
Dim i As Long, Upper As Long
If TypeName(va1) = "Empty" Then
va1 = va2
Else
Upper = UBound(va1)
If LBound(va2) = 0 Then Upper = Upper + 1
ReDim Preserve va1(LBound(va1) To UBound(va1) + UBound(va2) -
LBound(va2) + 1)
For i = LBound(va2) To UBound(va2)
va1(Upper + i) = va2(i)
Next i
End If
ArrayUnion = va1
End Function

Thanks

EM

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
Create formula that combines numbers from multiple workBOOKS? Sarah@LaborSource[_2_] Excel Discussion (Misc queries) 1 July 24th 09 07:04 PM
How do I create a custom button that combines format settings? PhillipB Excel Worksheet Functions 2 April 30th 09 03:05 PM
How do I combines data from multi-worksheets into one in ascendin Kara D. Sanders Excel Worksheet Functions 1 May 19th 06 09:25 AM
How do I make a sheet that combines all tabbed sheets & update as. ahmebah New Users to Excel 2 January 31st 05 03:17 PM
eomonth funciton in VBA ExcelMonkey[_83_] Excel Programming 2 February 11th 04 04:25 PM


All times are GMT +1. The time now is 09:43 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"