The code below is looking through items in Column A on sheet 'Key', then find match in Column A of sheet 'Match1' and copy the first 8 cells of each matched row on sheet 'Match1' to sheet 'Result'.
Can you please look through the following questions by priority? Okay to not have all three questions resolved.
Q1: How can I optimize the code below as the copy and paste takes long time to run because it's going through row by row on both Sheet 1 and Sheet 2? Is there a faster copy & paste method? Formatting doesn't matter.
Q2: If there are items not found on Sheet 'Match1', then we need to see if there is a match on Sheet 'Match2'. But this should only look up and paste rows that are not already on 'Result' tab. How to do this?
Q3: Once a match is found, can column B of sheet 'Key' tab populate 'found' so we can tell which items have a match?
________________________________________________________________
Sub FindItems()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim c As Range, d As Range
Dim LastRow As Long
Worksheets("Key").Activate
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For Each c In Range("A1:A" & LastRow)
For Each d In Worksheets("Match1").Range("A1:A206")
If c = d Then
c.Resize(1, 8).Copy
Worksheets("Result").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Exit For
End If
Next
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
MsgBox ("Completed")
End Sub
Can you please look through the following questions by priority? Okay to not have all three questions resolved.
Q1: How can I optimize the code below as the copy and paste takes long time to run because it's going through row by row on both Sheet 1 and Sheet 2? Is there a faster copy & paste method? Formatting doesn't matter.
Q2: If there are items not found on Sheet 'Match1', then we need to see if there is a match on Sheet 'Match2'. But this should only look up and paste rows that are not already on 'Result' tab. How to do this?
Q3: Once a match is found, can column B of sheet 'Key' tab populate 'found' so we can tell which items have a match?
________________________________________________________________
Sub FindItems()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim c As Range, d As Range
Dim LastRow As Long
Worksheets("Key").Activate
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For Each c In Range("A1:A" & LastRow)
For Each d In Worksheets("Match1").Range("A1:A206")
If c = d Then
c.Resize(1, 8).Copy
Worksheets("Result").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Exit For
End If
Next
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
MsgBox ("Completed")
End Sub