Page 1 of 1

list visible

Posted: Sun May 17, 2020 12:28 pm
by sna
Hi Dear
I have a problem with macro to list all visible sheets.
Here's a code from my friend
Sub test()
Dim i As integer
Dim sh As Worksheet
Sheets.add after:=Sheets(Sheets.count)
For Each sh in ThisWorkbook.Worksheets
i=i+1
If sh.Visible=xlSheetVisible Then
Cells(i,1).Value=sh.Name
End if
Next
End Sub

But it is no luck, what is going wrong?


Best wishes,

Re: list visible

Posted: Sun May 17, 2020 3:35 pm
by snasui
:D Please post your code in the form of 'code style' and attach the example file for easy to test.

Re: list visible

Posted: Sun May 17, 2020 3:59 pm
by sna
Dear ,,
How can I post code in form of 'Code style'?

Best regards

Re: list visible

Posted: Sun May 17, 2020 4:17 pm
by snasui

Re: list visible

Posted: Sun May 17, 2020 7:49 pm
by sna

Code: Select all

Sub test()
Dim i As integer
Dim sh As Worksheet
Sheets.add after:=Sheets(Sheets.count)
For Each sh in ThisWorkbook.Worksheets
i=i+1
If sh.Visible=xlSheetVisible Then
Cells(i,1).Value=sh.Name
End if
Next
End Sub

Re: list visible

Posted: Sun May 17, 2020 8:21 pm
by snasui
:D You can use this code for listing all visible sheets.

Code: Select all

Dim i As Integer, sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
    If sh.Visible = xlSheetVisible Then
        i = i + 1
        Cells(i, 1).Value = sh.Name
    End If
Next