list sheets in workbook

J

John

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...
 
M

Mike H

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
 
C

Chip Pearson

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)
 
S

Shane Devenshire

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top