我对自己的代码有些迷惑。基本上,如果满足某些条件,该代码会将某些行从一个工作表复制并粘贴到不同的工作簿。
也有两个循环。 1.工作流-遍历每个工作簿名称(对于j = 2到10) 2.遍历表中的每一行(i = 16到最后一行)。
我还要补充一个条件是,如果Mastersheet(i,1)中的值已经在工作簿的A列中,则什么也不做,转到下一个i。
下面是代码:
Sub copypaste()
Dim i As Integer
Dim j As Integer
Dim strFileName As String
Dim strFilePath As String
Getbook = ActiveWorkbook.Name
lastrow = Worksheets("Master").Range("D16").End(xlDown).Row
Application.screenupdating = False
strFilePath = "C:\Users\mxr0520\Desktop\CTA SSS\"
For j = 2 To 10
For i = 16 To lastrow
Workbooks(Getbook).Activate
If Workbooks(Getbook).Worksheets("Master").Cells(i, 11) = Worksheets("Master").Range("A10") Then
workstream = Workbooks(Getbook).Worksheets("Database").Cells(j, 2).Value
strFileName = workstream & ".xlsm"
If Workbooks(Getbook).Worksheets("Master").Cells(i, 4) = workstream Then
Workbooks(Getbook).Worksheets("Master").Range(Cells(i, 1), Cells(i, 16)).Select
Selection.Copy
Set wbkopen = Workbooks.Open(strFilePath & strFileName, False, False)
If Worksheets(workstream).Range("A16") = "" Then
Worksheets(workstream).Range("A16").PasteSpecial Paste:=xlPasteValues
Else
LastRow2 = Worksheets(workstream).Range("A15").End(xlDown).Row
Worksheets(workstream).Cells(LastRow2 + 1, 1).PasteSpecial Paste:=xlPasteValues
End If
Workbooks(workstream & ".xlsm").Close savechanges:=True
Else
End If
Else
End If
Next i
Next j
Application.screenupdating = True
Application.CutCopyMode = False
Range("A1").Select
MsgBox "Done"
End Sub
谢谢!