Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Mergeing two Arrays

This will merge two zero-based arrays A1() and A2() into
zero-based array A3().

Dave Ring

Sub Merge(A1(), A2(), A3())
Dim N1&, N2&, N3&, I&, J&, K&

N1 = UBound(A1): N2 = UBound(A3): N3 = N1 + N2
Redim A3(0 to N3)
I = 0: J = 0: K = 0
Do
If A1(I) <= A2(J) Then
A3(K) = A1(I): I = I + 1: K = K + 1
If I N1 Then
Do
A3(K) = A2(J): J = J + 1: K = K + 1
Loop Until J N2
Exit Do
End If
Else
A3(K) = A2(J): J = J + 1: K = K + 1
If J N2 Then
Do
A3(K) = A1(I): I = I + 1: K = K + 1
Loop Until I N1
Exit Do
End If
End If
Loop
End Sub

Paul W Smith wrote:

Has anyone got any sample code for merging two sorted one dimensional arrays
into one sorted new one?

e.g.

A1 = (2, 4, 6, 8)
A2 = (2, 3, 4, 9, 10)

RESULT = (2, 3, 4, 6, 8, 9, 10)



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
Arrays David Excel Discussion (Misc queries) 2 May 12th 09 10:16 PM
Mergeing Cells maths15 Excel Worksheet Functions 4 April 7th 08 11:02 PM
mergeing cells and wrapping text leo Excel Discussion (Misc queries) 2 March 21st 07 06:51 PM
Mergeing two Arrays Dave Peterson[_3_] Excel Programming 0 September 30th 03 02:30 AM
Mergeing two Arrays merjet Excel Programming 0 September 30th 03 02:24 AM


All times are GMT +1. The time now is 07:05 AM.

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"