我想将数据从一个工作表复制到另一个工作表。我。我有一个大数据电子表格,我想只复制一些数据(取决于sheet2的第一列中给出的数据)。我想仅为sheet2中的234个条目复制数据。但如果我运行此代码,它就不会停止。为什么?代码有什么问题?
Sub transferdata()
Dim i As Long, j As Long, lastrow1 As Long, lastrow2 As Long
Dim Mat As Variant
lastrow1 = Workbooks("Database").Sheets("DataBase").Range("K" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow1
Mat = Workbooks("Database").Sheets("DataBase").Cells(i, "K").Value
lastrow2 = Workbooks("Test").Sheets("TransferData").Range("A" & Rows.Count).End(xlUp).Row
For j = 2 To lastrow2
If Workbooks("Test").Sheets("TransferData").Cells(j, "A").Value = Mat Then
Workbooks("Database").Sheets("DataBase").Activate
Workbooks("Database").Sheets("DataBase").Cells(i, "L").Copy
Workbooks("Test").Sheets("TransferData").Activate
Workbooks("Test").Sheets("TransferData").Cells(j, "B").Select
Workbooks("Test").Sheets("TransferData").PasteSpecial
End If
Next j
Application.CutCopyMode = False
Next i
End Sub