Hi all,
I have two arrays i need to do an element comparison on.
Arr is the first array, which is a list from a worksheet range.
ArrRestults is the return results from an sql query, using Arr in the where clause.
ArrResults will contain the same or less data/elements than Arr.
Is there a simple way to loop through Arr, and find any element/data that isn't in ArrResults, and if found, put that value into a third array? (i.e. ArrFound)
Cheers,
Skmr3.
AHi skimmer333
welcome to the forum
one possible way would be with a Dictionary
With CreateObject("Scripting.Dictionary") .comparemode = vbTextCompare For i = 1 To UBound(myarray, 1) If Not .Exists(myarray(i, 1)) Then n = n + 1 .Add myarray(i, 1), n End If Next For i = 1 To UBound(myarrayTwo, 1) If Not .Exists(myarrayTwo(i, 1)) Then n = n + 1 .Add myarrayTwo(i, 1), n Else MsgBox myarrayTwo(i, 1) & " Exists" End If Next End With
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
Thanks for your reply pike.
Your code got me thinking again, and I got this to work:
It dumps out all values that are in Arr and also in ArrResults.For Each c In Arr() For i = LBound(ArrResults) To UBound(ArrResults) If c = ArrResults(i) Then ActiveCell.Value = c ActiveCell.Offset(1, 0).Activate End If Next Next c
Which looks correct.
Now, i'm just trying to work out the reverse.
Dump out all values that are in Arr but not in ArrResults.
/Skmr3.
Hi skimmer333,
yep, it will work fine. May be a little slow with large data.Dict are quicker.
Another way would be to compare the arrays as they are created
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks