嵌套 for 循环重复结果

时间:2021-01-20 13:31:52

标签: excel vba

所以我试图将多张工作表中的数据复制到一张工作表中。我遇到的问题是它重复了一张符合 IF 语句的工作表的结果 5 次(因为我有 5 张工作表)。这将如何在 VBA 中解决?

Dim Current As Worksheet
Dim j As Integer
Dim Target As Worksheet

Set Target = ActiveWorkbook.Worksheets("CopyToThis")

j = 1     ' Start copying to row 1 in target sheet
    For Each Current In Worksheets
        For Each c In Current.Range("I:I")
            If c > 0 Then
                MsgBox (Current.Name)
               Current.Rows(c.Row).Columns("A:F").Copy Target.Rows(j) 'Copy only columns A to F
               j = j + 1
            End If
        Next c
    
    Next

0 个答案:

没有答案