Please help - how to optimize all the copying and pasting

lyq0077

New Member
Joined
Jul 27, 2015
Messages
10
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of your 3 sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top