Making a If True Double Loop Copy Special Paste Faster

Hmerman

Board Regular
Joined
Oct 2, 2016
Messages
102
Hello,
Hope you are well.

I have code that looks on Sheet 7 and Sheet 18 for a cells thats values are equal. Then pastes contiguous and non contiguous values in the same row as the equal cell in Sheet 7 to Sheet 18.

It takes a very long time. Can someone please help to make it faster?

<code>
Dim varResponse As String
Dim i As Long, x As Long

varResponse = MsgBox("Transfer Info to Inventory", vbYesNo, "Selection")
If varResponse <> vbYes Then Exit Sub

Application.ScreenUpdating = False
With Sheet18​
lastLookup = Sheet7.Range("C" & .Rows.Count).End(xlUp).row​
lastrow = .Range("C" & .Rows.Count).End(xlUp).row​
For i = 2 To lastrow​
For x = 2 To lastLookup​
If (Sheet7.Cells(x, 3) = .Cells(i, 3).Value) Then​
Sheet7.Cells(x, 2).Copy​
.Cells(i, 6).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 4).Copy​
.Cells(i, 7).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 8).Copy​
.Cells(i, 8).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 12).Copy​
.Cells(i, 9).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 14).Copy​
.Cells(i, 10).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 15).Copy​
.Cells(i, 11).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 16).Copy​
.Cells(i, 12).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 17).Copy​
.Cells(i, 13).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 18).Copy​
.Cells(i, 14).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 19).Copy​
.Cells(i, 15).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 20).Copy​
.Cells(i, 16).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 21).Copy​
.Cells(i, 17).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 22).Copy​
.Cells(i, 18).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 23).Copy​
.Cells(i, 19).PasteSpecial xlPasteValues​
Sheet7.Cells(x, 24).Copy​
.Cells(i, 20).PasteSpecial xlPasteValues​
End If​
Next​
Next
MsgBox "Complete!"


End With
Application.ScreenUpdating = True
</code>

Any advice or suggestion will be helpful.

Regards,
Herman
 
Glad to help & thanks for the feedback
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,216,030
Messages
6,128,405
Members
449,448
Latest member
Andrew Slatter

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