Visible WorkSheets

  • Thread starter Thread starter charles
  • Start date Start date
C

charles

I need to know how many worksheets are set to ".visible"
in my workbook.

Can you tell me how to do that ,and, also how to list them
using VBA.


Thanks

CharlesW
 
Hi Charles

Try this

Sub test()
'xlSheetVisible = -1
Dim sh As Worksheet
Dim N As Integer
N = 0
For Each sh In ThisWorkbook.Worksheets
If sh.Visible = -1 Then
N = N + 1
' Cells(N, 1).Value = sh.Name
' you can list them on the activesheet like this
End If
Next
With ThisWorkbook
msgbox "There are " & N & " Visible worksheets of the " _
& .Worksheets.Count & " Worksheets"
End With
End Sub
 
Charles,

You can also change the line

If sh.Visible = -1 Then

to be

If sh.Visible = xlSheetVisible Then

which is a bit more descriptive, or even

If sh.Visible Then
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top