Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default List of all visible worksheets

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default List of all visible worksheets

Sub listvisiblesheets()
mc = 2
For Each ws In Worksheets
If ws.Visible = True Then
Cells(mc, 2) = ws.Name
mc = mc + 1
End If
Next
End Sub

--
Don Guillett
SalesAid Software

"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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default List of all visible worksheets

Hi Don,

Thanks a lot, this works fine!

Gert-Jan

"Don Guillett" schreef in bericht
...
Sub listvisiblesheets()
mc = 2
For Each ws In Worksheets
If ws.Visible = True Then
Cells(mc, 2) = ws.Name
mc = mc + 1
End If
Next
End Sub

--
Don Guillett
SalesAid Software

"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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Status bar not visible in my .xlsx worksheets. Barbara Excel Discussion (Misc queries) 0 March 24th 09 06:02 PM
Dropdown List - list item endings not visible if column too narrow AK9955 Excel Discussion (Misc queries) 2 April 27th 07 09:02 AM
Worksheets not visible in Excel XP [email protected] Excel Programming 7 March 30th 05 09:32 PM
Visible WorkSheets [email protected] Excel Programming 3 January 24th 05 09:14 AM
Visible property on Worksheets Russell Lucas Excel Programming 5 February 5th 04 03:26 PM


All times are GMT +1. The time now is 01:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"