If you sort the array and then do check, that will also be longer. The best way is to copy the array to excel cells and then sort them and then compare them. that is the fastest...it ‘s very long. How can I do it faster?
For Example (Please amend it as per you requirements...)
vb Code:
Sub aaa() 'Defining my array for test purpose Dim ar(21) For i = 1 To 20 ar(i) = "aaa" & i 'Creating a duplicate value ar(21) = "aaa1" Next i 'Copy Data to Sheet For j = 1 To 21 Sheets("sheet1").Range("A" & j) = ar(j) Next j 'Sort The data Range("A1").Select Range(Selection, Selection.End(xlDown)).Select Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal 'Do the Comparing For k = 1 To 21 If Range("A" & (k + 1)).Value = Range("A" & k).Value Then MsgBox "Match Found" End If Next k End Sub




Reply With Quote