全シート数をカウントする
実行プログラム
1 2 3 4 5 |
Sub Sample6_3_1() MsgBox "ワークシート数:" & CStr(Worksheets.Count) End Sub |
実行前
![](http://excelmemo.com/wp-content/uploads/PIC060301-300x232.jpg)
実行後
![](http://excelmemo.com/wp-content/uploads/PIC060302-300x232.jpg)
- Long型の値を返します。
- 非表示のシートもカウントされます。
表示されているシートのみをカウントする
実行プログラム
1 2 3 4 5 6 7 8 9 10 11 12 |
Sub Sample6_3_2() Dim intCnt As Integer Dim i As Integer For i = 1 To Worksheets.Count If Worksheets(i).Visible Then intCnt = intCnt + 1 Next MsgBox "表示ワークシート数:" & CStr(intCnt) End Sub |
「Sheet3」が非表示になっていることを確認。