我目前有一个VB宏,它将值从一个表复制到另一个表.然而,目前,VB的编写方式是它将逐行执行,并且由于它经历了几千行,因此运行速度非常慢.我想知道如何更好地改变我的VB进行批量复制粘贴以减少等待时间.代码是:
Sub copypaste_settlement_rows()
Dim LastRow As Long
Application.ScreenUpdating = False
Sheets("Settlement Template").Select
'find last row in column A
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To LastRow
Cells(x, 1).Resize(1, 42).Copy
Sheets("PIVOT DATA").Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Sheets("Settlement Template").Select
Next x
Sheets(">> START HERE <<").Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Run Code Online (Sandbox Code Playgroud)