【发布时间】:2020-11-27 08:29:49
【问题描述】:
我有一个工作代码,用于将大量数据从月表复制到日表。大约有 30 列数据要复制超过 2000 行。我不知道如何加快这项工作,因为即使复制一列也需要大约 3 分钟。对于所有 30 列,我都必须这样做。月表中的列顺序与日表不同;例如。月表 D 列可能代表日表的 P 列。如果学过的人能帮助改进代码,我将不胜感激。
PJ
Sub COPY2()
Dim i As Long, j As Long, lastrow1 As Long, Lastrow2 As Long, myname As String
Dim SWB As Workbook, TWB As Workbook, Sws As Worksheet, Tws As Worksheet
Set SWB = ActiveWorkbook
Set Sws = SWB.Sheets("SHEET1")
Windows("DAILY.xlsX").Activate
Set TWB = ActiveWorkbook
Set Tws = TWB.Sheets("Sheet1")
lastrow1 = Sws.Range("A" & Rows.Count).End(xlUp).Row
Lastrow2 = Tws.Range("A" & Rows.Count).End(xlUp).Row
Sws.Activate
For i = 2 To lastrow1
myname = Sws.Cells(i, "B").Value
Tws.Activate
For j = 2 To Lastrow2
If Tws.Cells(j, "D").Value = myname Then Tws.Cells(j, "P").Value = Sws.Cells(i, "D").Value
If Tws.Cells(j, "P").Value = Sws.Cells(i, "D").Value Then Exit For
Next j
Next i
End Sub
【问题讨论】: