VBA宏陷入循环

时间:2018-09-18 21:52:15

标签: excel vba

我已经编写了一个(我认为很简单)的宏,以便在我的工作簿的44张纸上重复相同的操作(不包括前5张)。

这是代码:

Sub LoopThroughSheets()
Dim ws As Worksheet
Dim Lastrow As Long
Dim i As Long
Dim rng As Range


For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Group Key" And ws.Name <> "AUX Key" And ws.Name <> "Start" And ws.Name <> "SSummary" And ws.Name <> "TSummary" Then
           'code omitted, but it essentially is adding a date column and a numbered row column in each worksheet/basic formatting     
    End If

Next ws

End Sub

一旦最后一张纸(命名为“ Tech”)被格式化,我该如何添加一段代码来结束循环?

1 个答案:

答案 0 :(得分:0)

我认为您只需要添加:

For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Group Key" And ws.Name <> "AUX Key" And ws.Name <> "Start" And ws.Name <> "SSummary" And ws.Name <> "TSummary" Then
           'code omitted, but it essentially is adding a date column and a numbered row column in each worksheet/basic formatting     
    End If
    If ws.Name = "Tech" Then Exit For '' THIS LINE
Next ws