View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
John[_88_] John[_88_] is offline
external usenet poster
 
Posts: 205
Default List of all visible worksheets

Gert-Jan,

You're almost there. Just add a If statement to check if the respective
sheet is visible:

Sub test()
Dim NumSheets As Integer
Dim sht As Object
NumSheets = Sheets.Count
For j = 1 To NumSheets
If Sheets(j).Visible = True Then
Cells(j + 1, 8) = Sheets(j).Name
End If
Next j
End Sub

You could also add a separate row counter to prevent any gaps in the list:

Sub test()
Dim NumSheets As Integer
Dim sht As Object
Dim iRow As Integer
'Set the start row
iRow = 2
NumSheets = Sheets.Count
For j = 1 To NumSheets
If Sheets(j).Visible = True Then
Cells(iRow, 8) = Sheets(j).Name
iRow = iRow + 1
End If
Next j
End Sub

Hope that helps

Best regards

John





"Gert-Jan" wrote in message
...
Hi,

Can anyone help me with writing a macro that lists all the sheets of of a
workbook to a certain range?

I have this:

Sub test()
Dim NumSheets As Integer
Dim sht As Object
NumSheets = Sheets.Count
For j = 1 To NumSheets
Cells(j + 1, 8) = Sheets(j).Name
Next j
End Sub

But it writes ALL sheetnames, not only the visible.

Thanks in advance, Gert-Jan