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

John Walkenbach has some sample code at:

http://j-walk.com/ss/excel/tips/tip47.htm

That builds a list of unique values using a collection and then sorts that
collection.

You could do the same type of thing:

Option Explicit
Sub RemoveDuplicates()
Dim Arr1 As Variant
Dim Arr2 As Variant
Dim Arr3 As Variant
Dim i As Long, j As Long
Dim Swap1, Swap2, Item
Dim NoDupes As Collection

Set NoDupes = New Collection

Arr1 = Array(2, 4, 6, 8)
Arr2 = Array(2, 3, 4, 9, 10)

On Error Resume Next
For i = LBound(Arr1) To UBound(Arr1)
NoDupes.Add Arr1(i), CStr(Arr1(i))
Next i
For i = LBound(Arr2) To UBound(Arr2)
NoDupes.Add Arr2(i), CStr(Arr2(i))
Next i
On Error GoTo 0

For i = 1 To NoDupes.Count - 1
For j = i + 1 To NoDupes.Count
If NoDupes(i) NoDupes(j) Then
Swap1 = NoDupes(i)
Swap2 = NoDupes(j)
NoDupes.Add Swap1, befo=j
NoDupes.Add Swap2, befo=i
NoDupes.Remove i + 1
NoDupes.Remove j + 1
End If
Next j
Next i

ReDim Arr3(1 To NoDupes.Count)
i = 0
For Each Item In NoDupes
i = i + 1
Arr3(i) = Item
Next Item

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)


--

Dave Peterson

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
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
3D Arrays DB Excel Worksheet Functions 2 October 10th 05 03:50 PM
Arrays Dan Excel Worksheet Functions 3 September 15th 05 07:36 AM
Mergeing two Arrays merjet Excel Programming 0 September 30th 03 02:24 AM


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