ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   List of all visible worksheets (https://www.excelbanter.com/excel-programming/378710-list-all-visible-worksheets.html)

Gert-Jan[_3_]

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



John[_88_]

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




Don Guillett

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




Gert-Jan[_2_]

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






Don Guillett

List of all visible worksheets
 
Glad to help.

--
Don Guillett
SalesAid Software

"Gert-Jan" wrote in message
.. .
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








John[_88_]

List of all visible worksheets
 
Me too! :)

John

"Don Guillett" wrote in message
...
Glad to help.

--
Don Guillett
SalesAid Software

"Gert-Jan" wrote in message
.. .
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










Don Guillett

List of all visible worksheets
 
The problem with yours is that it left blank rows for the hidden sheets
--
Don Guillett
SalesAid Software

"John" wrote in message
...
Me too! :)

John

"Don Guillett" wrote in message
...
Glad to help.

--
Don Guillett
SalesAid Software

"Gert-Jan" wrote in message
.. .
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












John[_88_]

List of all visible worksheets
 
Hello Don,

Yes I know. That's why I added the second sub in my post.

Never mind, I can deal with the pain :)

Best regards

John

"Don Guillett" wrote in message
...
The problem with yours is that it left blank rows for the hidden sheets
--
Don Guillett
SalesAid Software

"John" wrote in message
...
Me too! :)

John

"Don Guillett" wrote in message
...
Glad to help.

--
Don Guillett
SalesAid Software

"Gert-Jan" wrote in message
.. .
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














Don Guillett

List of all visible worksheets
 
I stand corrected. I guess OP and I didn't see it.

--
Don Guillett
SalesAid Software

"John" wrote in message
...
Hello Don,

Yes I know. That's why I added the second sub in my post.

Never mind, I can deal with the pain :)

Best regards

John

"Don Guillett" wrote in message
...
The problem with yours is that it left blank rows for the hidden sheets
--
Don Guillett
SalesAid Software

"John" wrote in message
...
Me too! :)

John

"Don Guillett" wrote in message
...
Glad to help.

--
Don Guillett
SalesAid Software

"Gert-Jan" wrote in message
.. .
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

















All times are GMT +1. The time now is 05:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com