I am trying to compare two columns in different worksheets to check if value in column A exist in column B.
When I am trying to transpose row value and store it into dictionary for comparison, run-time error '13' is triggered.
Here is the code:
Sub Compare()
Dim rngA As Range, rngB As Range
Dim dict As Object, rw As Range
Dim a As Application, tmp As String
Dim Row1Last As Long
Dim Row2Last As Long
Set a = Application
Set dict = CreateObject("scripting.dictionary")
Set sht1 = Worksheets("list_Facility_BOS")
Set sht2 = Worksheets("List_Facility_PG")
With Sheets("list_Facility_BOS")
Row1Last = .Cells(Rows.Count, "G").End(xlUp).Row
End With
With Sheets("List_Facility_PG")
Row2Last = .Cells(Rows.Count, "H").End(xlUp).Row
End With
Set rngA = sht1.Range("G2:G" & Row1Last)
Set rngB = sht2.Range("H2:H" & Row2Last)
For Each rw In rngA.Rows
dict.Add Join(a.Transpose(a.Transpose(rw.Value)), Chr(0)), rw.Row
Next rw
For Each rw In rngB.Rows
tmp = Join(a.Transpose(a.Transpose(rw.Value)), Chr(0))
If dict.exists(tmp) Then
Else
rw.Cells(1).Interior.ColorIndex = 3
End If
Next rw
End Sub
I attempt to compare a 20k rows record column against another 20k rows column in another worksheet. Error '13' was trigger in this line of code:
dict.Add Join(a.Transpose(a.Transpose(rw.Value)), Chr(0)), rw.Row
I am new to excel VBA programming, sorry if I could'nt explain it clearly. Please let me know if there is any mistakes in my code.