Hello, i have two lists that i need to compare, and if i find a match, i want to copy the entire row to athird sheet. i have one tab with ID numbers, which are only listed once. my other tab has the data and ID is present in many of the rows. Right now i added the ID's to a dictionary and then loop through the data to see if the dictionary entry exists, if so it does the copy. it took 50 seconds to loop through 1500 rows, how can i get this to run quicker?
Code:
Sub transfer()
Dim row As Long
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Dim org As String
Dim i As Integer, k As Variant
row = Sheets("Swap").UsedRange.Rows.Count
k = 2
Sheets("Roster").Rows(1).Copy Sheets("_Roster").Range("A1")
For i = 2 To row
org = Sheets("Swap").Range("D" & i).Value
If dict.exists(org) Then
Else
dict.Add Key:=org, Item:=org
End If
Next i
row = Sheets("Roster").UsedRange.Rows.Count
For i = 2 To row
org = Sheets("Roster").Range("i" & i).Value
If dict.exists(org) Then
Sheets("Roster").Rows(i).Copy Sheets("_Roster").Range("A" & k)
k = k + 1
Else
'dict.Add Key:=org, Item:=org
End If
Next i
End Sub