Remove Duplicates With Condition in VBA Array
At the request of a user, I have rewritten this question with more
information.
I have an array with three rows. The first contains an ID. The last
contains a numeric value. I need to remove duplicate ID's. If there is a
duplicate, I need to retain the maximum numeric value. There are are
multiple ID's with the same numeric value, I want to keep the first record
of the ID.
The following code shows what I have, and what I need to accomplish:
Sub TestArray()
Dim TestArray() As Variant
Dim DesiredResults() As Variant
TestArray = Array(Array("a", "a", "a", "b", "b", "b"), _
Array(1, 2, 3, 1, 2, 3), _
Array(10, 20, 30, 10, 10, 10))
DesiredResults = Array(Array("a", "b"), Array(3, 1), Array(30, 10))
End Sub
Is there some way to loop through the array and find duplicates and then
compare them? I could do this easily in SQL but I am struggling in VBA.
No comments:
Post a Comment