ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   list sheets in workbook (https://www.excelbanter.com/excel-discussion-misc-queries/223808-list-sheets-workbook.html)

John

list sheets in workbook
 
Hello to all...
I have found this community to be very helpful for a new user like me. I
have used many examples displayed throughout the sessions. What I would like
to do is list the sheets in my workbook on sheet 1 but exclude sheet 1 in the
list, starting with sheet 2 through sheet end.
I have found the code that list all sheets which will work but I would like
to eliminate the first sheet though.

Any example of code would be nice. Thanks in advance...


Mike H

list sheets in workbook
 
Hi,

I am assuming sheet1 is the first sheet in your workbook. Right click a
sheet tab, view code and paste this in and run it

Sub Sonic()
For x = 2 To Worksheets.Count
Sheets("Sheet1").Cells(x - 1, 1).Value = Sheets(x).Name
Next
End Sub

If sheet 1 isn't the first sheet then use this

Sub Sonic()
For x = 1 To Worksheets.Count
If Sheets(x).Name < "Sheet1" Then
Sheets("Sheet1").Cells(x - 1, 1).Value = Sheets(x).Name
End If
Next
End Sub


Mike

"John" wrote:

Hello to all...
I have found this community to be very helpful for a new user like me. I
have used many examples displayed throughout the sessions. What I would like
to do is list the sheets in my workbook on sheet 1 but exclude sheet 1 in the
list, starting with sheet 2 through sheet end.
I have found the code that list all sheets which will work but I would like
to eliminate the first sheet though.

Any example of code would be nice. Thanks in advance...


Chip Pearson

list sheets in workbook
 
Try something like

Sub AAA()
Dim StartCell As Range
Dim N As Long
Set StartCell = Range("A1") '<<< CHANGE
With ThisWorkbook.Worksheets
For N = 2 To .Count
StartCell(N - 1, 1).Value = .Item(N).Name
Next N
End With
End Sub

Change the reference to A1 to the cell in which you want to list to
begin.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Tue, 10 Mar 2009 14:35:01 -0700, John
wrote:

Hello to all...
I have found this community to be very helpful for a new user like me. I
have used many examples displayed throughout the sessions. What I would like
to do is list the sheets in my workbook on sheet 1 but exclude sheet 1 in the
list, starting with sheet 2 through sheet end.
I have found the code that list all sheets which will work but I would like
to eliminate the first sheet though.

Any example of code would be nice. Thanks in advance...


Shane Devenshire

list sheets in workbook
 
Hi,

And here is another approach

Sub GetNames()
Dim sh As Worksheet
Dim I As Integer
For Each sh In Worksheets
If sh.Index 1 Then
Sheets(1).[A1].Offset(I) = sh.Name
I = I + 1
End If
Next sh
End Sub

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"John" wrote:

Hello to all...
I have found this community to be very helpful for a new user like me. I
have used many examples displayed throughout the sessions. What I would like
to do is list the sheets in my workbook on sheet 1 but exclude sheet 1 in the
list, starting with sheet 2 through sheet end.
I have found the code that list all sheets which will work but I would like
to eliminate the first sheet though.

Any example of code would be nice. Thanks in advance...



All times are GMT +1. The time now is 12:57 PM.

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