I have two macros. One of them creates an array based on a range. The second will take that array, go through it and remove any duplicate entries. I then want the second macro to return an Array that I can continue using in the first macro.
Here's what I've tried so far:
This is to get the array:
Sub array_Test()
Dim array1() As Variant
ReDim array1(1 To 10)
array1 = Range("A1:A10")
GEN_USE_Remove_Duplicates_from_Array (array1)
Dim i As Integer
Debug.Print Join(array1, "/") 'Now that array1 has had duplicates removed, print the remaining numbers. This is where I don't know what to do
For i = 0 To UBound(array1)
Range(Cells(i + 1, 2).Value) = array1(i + 1)
Next i
End Sub
And here's that GEN_USE_Remove_Duplicates... sub:
Sub GEN_USE_Remove_Duplicates_from_Array(arr As Variant)
Dim Array_1
Array_1 = arr
Dim Array_2()
Dim Array_toRemove()
Dim dic As New Scripting.Dictionary
Dim arrItem, x As Long
For Each arrItem In Array_1
If Not dic.Exists(arrItem) Then
dic.Add arrItem, arrItem
End If
Next
Array_2 = dic.Keys
Debug.Print Join(Array_2, "/")
GEN_USE_Remove_Duplicates_from_Array = Array_2
End Sub
That successfully keeps only unique values. Now, how do I get that result (Array_2) to be used in the array_Test sub? Do I need to create a function instead of a Sub?
Thanks so much for any advice/help/tips!
function GEN_USE_Remove_Duplicates_from_Array(arr As Variant) ... end functionand assign the returned array to an array likearray1 = GEN_USE_Remove_Duplicates_from_Array (array1).array1 = GEN_USE_Remove...(array1). Thanks so much Jeeped, as always!! Edit: Meta question - can I mark your comment as an answer? Or can you put that in an "Answer" so I can do so, so you get the credit you deserve?