如果特定列中的每行都包含“是”,则需要将粘贴复制到其他工作簿
我试图创build一个macros,它通过列“C”,并在包含“是”的列“C”中的每一行,然后与“B2”中的链接的文件应自动打开,并在“F2 “应该在范围”I2“中打开的文件中作为值复制和粘贴,之后应该用从”H2“取出的新文件名保存文件,最后closures文件。
下面是我试过的macros,但没有成功。
示例文件
Sub Copy() Dim SWB As Workbook Dim TWB As Workbook Dim NewFileName As String Dim OldFileName As String Dim rng As Range Dim row As Range Set SWB = ThisWorkbook Set SWS = SWB.Sheets("Sheet1") NewFileName = Range("H2").Value OldFileName = Range("B2").Value response = MsgBox("Have you reviewed the files? This is a notification.", vbYesNo, "Confirmation") If response = vbNo Then Exit Sub End If Application.ScreenUpdating = 0 Set rng = Range("A1:Q500") For Each row In rng.Rows If (Cells((i + 1), 3).Value) = "yes" Then On Error Resume Next With SWS.Range("F2").Copy End With Set TWB = Workbooks.Open(OldFileName) With TWB.Sheets("CFF 12M") .Range("I2").PasteSpecial Paste:=xlPasteValues End With TWB.SaveAs filename:=NewFileName Application.CutCopyMode = False TWB.Close Savechanges = True End If Next End Sub