微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何遍历除一张以外的所有图纸?

如何解决如何遍历除一张以外的所有图纸?

我想循环浏览工作表,如果满足内部条件,则将其复制到我的“ Controle”工作表中。

我的代码没有循环。

我在“控件”工作表中有一个列表,其中包含所有工作表中的所有彩色单元格。该代码必须跳过名称为“ Controle”的工作表,因为在这里我将单元格复制到其中。

Sub dubbelewaarden()
Dim cell As Range
Dim sht As Worksheet
For Each sht In Worksheets
    If Not sht.Name <> "Controle" Then
        For Each cell In Range("A2",Range("A2").End(xlDown))
            If cell.Interior.ColorIndex = 3 Then
                cell.EntireRow.copy Destination:=Sheets("Controle").Range("A" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next cell
    End If
Next sht

End Sub
```

解决方法

这只是将loop变量调整到工作表的一种情况,否则将假定为活动工作表。在线有很多参考。

Sub Dubbelewaarden()

Dim cell As Range
Dim sht As Worksheet

For Each sht In Worksheets
    If sht.Name <> "Controle" Then
        'tie reference to sheet in loop
        For Each cell In sht.Range("A2",sht.Range("A" & Rows.Count).End(xlUp))
            If cell.Interior.ColorIndex = 3 Then
                cell.EntireRow.Copy Destination:=Sheets("Controle").Range("A" & Rows.Count).End(xlUp).Offset(1)
            End If
        Next cell
    End If
Next sht

End Sub

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。