• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Tweak Matching Macro

Nujl

New Member
Hello this is my first time here, I have been looking and looking for code on matching across sheets, I found this thread: http://forum.chandoo.org/threads/faster-way-to-match-two-columns.16280/#post-98742 on your forum it had the following

I tried it and it was wonderfully fast on a single sheet, like the the author of the thread I need it something that will work across sheets and return row, in the same workbook.

Is this possible?

Thanks in advance for your consideration

Nujl

Code:
Sub FindMatches()
Dim objDic As Object: Set objDic = CreateObject("Scripting.Dictionary")
Dim lngLastRow As Long: lngLastRow = Range("A" & Rows.Count).End(xlUp).Row
Dim varSource As Variant: varSource = Range("B2:B" & lngLastRow).Value
Dim varDestn As Variant: varDestn = Range("D2:D" & lngLastRow).Value
'\\ Build source array
For i = LBound(varSource) To UBound(varSource)
  With objDic
  .comparemode = vbTextCompare
  If Not .exists(varSource(i, 1)) Then
  .Add varSource(i, 1), varSource(i, 1)
  End If
  End With
Next i
'\\ Build Destination array
For i = LBound(varDestn) To UBound(varDestn)
  With objDic
  .comparemode = vbTextCompare
  If Not .exists(varDestn(i, 1)) Then
  varDestn(i, 1) = "#N/A"
  End If
  End With
Next i
'\\ Post back the results
Range("D2:D" & lngLastRow).Value = varDestn
End Sub
 
Last edited:
Back
Top