我被困在正确读取的地方,我有两行满足“如果”条件,但它在不同的纸张上复制了 A 行两次,而不是第 8 行和第 10 行。有没有办法让它识别一个一次一个单元格,如果满足条件则复制它。
我尝试过以下代码
Sub RunReport()
Dim srcSheet As Worksheet
Dim rptSheet As Worksheet
Dim i As Range
Dim srcSheets As Variant
Set rptSheet = ThisWorkbook.Sheets("Report")
Set srcSheets = Worksheets(Array("SheetA", "SheetB", "SheetC", "SheetD"))
For Each srcSheet In srcSheets
For Each i In srcSheet.Range("A5:W358")
If srcSheet.Range(i, "B").Value <> "" And srcSheet.Range(i, "O").Value = "" Then
srcSheet.Cells(i).EntireRow.Copy Destination = rptSheet.Cells(rptSheet.Rows.Count, "A").End(xlUp).Offset(1, 0)
End If
Next i
Next srcSheet
End Sub
i
是一个范围对象,代码应该如下所示。i.EntireRow.Copy Destination:= rptSheet.Cells(rptSheet.Rows.Count, "A").End(xlUp).Offset(1, 0)