Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Mergeing Cells | Excel Worksheet Functions | |||
mergeing cells and wrapping text | Excel Discussion (Misc queries) | |||
3D Arrays | Excel Worksheet Functions | |||
Arrays | Excel Worksheet Functions | |||
Mergeing two Arrays | Excel Programming |