1

我正在尝试计算名称相似的工作表的数量(例如所有以“East”开头的)。

这是我用来计算床单的代码:

Dim wb As Workbook
Dim ws As Worksheet
Dim myTotal As Long
Dim wsTotal As Long

For Each wb In Workbooks
    For Each ws In Worksheets
        If ws.Name Like "20 Out of Court" & "*" Then myTotal = myTotal + 1
    Next ws
Next wb
wsTotal = myTotal

有时它会使某些机器上的工作表总数翻倍。

4

1 回答 1

1

试试下面的代码:

Sub sample()

    Dim wb As Workbook
    Dim ws As Worksheet
    Dim myTotal As Long
    Dim wsTotal As Long

    For Each wb In Workbooks
        For Each ws In Worksheets
            Debug.Print ws.Name
            If InStr(1,left(ws.Name,4), "East", vbTextCompare) > 0 Then ' will check for start with "East"..
                myTotal = myTotal + 1
            End If
        Next ws
    Next wb
    wsTotal = myTotal
End Sub
于 2013-02-28T15:19:09.367 回答