首页 > 解决方案 > 嵌套 for 循环重复结果

问题描述

所以我试图将多张纸上的数据复制到一张纸上。我遇到的问题是它重复了一张适合 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

标签: excelvba

解决方案


推荐阅读