Tim Hanson
Member
I am trying to use a Dictionary object for first time and am confused!
I am trying to compare columns on 2 different sheets then post back to a 3rd sheet
I get the proper number of matched rows but no matches( they are all "0")
I uploaded a workbook
In module2 I have a matching Macro "RemoveRowsByMatch" I used the generate the "Want" tab, I am trying to duplicate "RemoveRowsByMatch" using a Dictionary object because I think it is faster and I am trying to get an idea of how to use a Dictionary objects
Thanks for any help on this
Thank you
I am trying to compare columns on 2 different sheets then post back to a 3rd sheet
I get the proper number of matched rows but no matches( they are all "0")
I uploaded a workbook
In module2 I have a matching Macro "RemoveRowsByMatch" I used the generate the "Want" tab, I am trying to duplicate "RemoveRowsByMatch" using a Dictionary object because I think it is faster and I am trying to get an idea of how to use a Dictionary objects
Thanks for any help on this
Thank you
Code:
Sub FindDistinct()
Dim dict As Object
Dim arr As Variant
Dim wsS As Worksheet, wsFind As Worksheet, wsPB As Worksheet
Dim Counter As Long
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Set dict = CreateObject("Scripting.Dictionary")
Set wsS = ThisWorkbook.Sheets("XXX")
Set wsFind = ThisWorkbook.Sheets("YYY")
Set wsPB = ThisWorkbook.Sheets("ZZZ")
arrS = wsS.Range("A2", wsS.Cells(wsS.Rows.Count, "A")).Value
arrFind = wsFind.Range("A2", wsFind.Cells(wsFind.Rows.Count, "A")).Value
With wsS
Set dict = CreateObject("Scripting.Dictionary")
dict.CompareMode = vbTextCompare
On Error Resume Next
For Counter = 1 To UBound(arrS, 1)
If Not dict.Exists(arrS(Counter, 1)) Then dict.Add arrS(Counter, 1), arrFind(Counter, 1)
Next
On Error GoTo 0
End With
With wsPB
.Range("A1") = "Dictionary"
arrS = dict.Items
.Range("A2").Resize(dict.Count, 1).Value = Application.Transpose(arr)
Set dic = Nothing
' Resize columns as needed
.Columns.AutoFit
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
MsgBox "Done"
End Sub