将复制粘贴的VBAmacros逐行更改为批量复制粘贴

我目前有一个VBmacros,将从一个表复制到另一个值。 然而,目前VB的编写方式是逐行执行,而且运行速度相当慢,因为它经历了几千行。 我想知道如何将最好的改变我的VB做一个批量复制粘贴,以减less等待时间。 代码是:

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 

这应该是瞬间的,它不使用剪贴板:

 Sub copypaste_settlement_rows() Dim v With Sheets("Settlement Template") v = .Cells(2, 1).Resize(.Cells(.Rows.Count, "A").End(xlUp).Row, 42) End With With Sheets("PIVOT DATA") .Cells(.Rows.Count, "A").End(xlUp).Resize(UBound(v), UBound(v, 2)) = v End With End Sub 

一个非常简单的方法(以及我在自己的代码中看到的最快的方法)是:

 ThisWorkbook.Worksheets("PIVOT DATA").Range("A2:A" & lastRow) = ThisWorkbook.Worksheets("Settlement Template").Range("A2:A" & lastRow).Value