Macro for listing sheet names

  • Thread starter Thread starter srctr
  • Start date Start date
S

srctr

I have this macro (inherited from another user) that will take all the sheet
names and put it in a list. My problem is it lists the last sheet first. I
need it skip the first sheet which is my master list and then starting with
the next sheet put them in order. Sheet1, Sheet2 etc. I know there is
something that is telling it what order to compile it, I just don't what.

Thanks,

cao

Sub WorksheetNamesList()
Dim wCtr As Long
Dim rCtr As Long
rCtr = 1
For wCtr = Worksheets.Count To 2 Step -1
rCtr = rCtr + 1
With ActiveSheet.Cells(rCtr, 1)
.NumberFormat = "@" 'text
.Value = Sheets(wCtr).Name
End With
Next wCtr

End Sub
 
Sub WorksheetNamesList()
Dim wCtr As Long
Dim rCtr As Long
rCtr = 1
For wCtr = 2 To Worksheets.Count
rCtr = rCtr + 1
With ActiveSheet.Cells(rCtr, 1)
.NumberFormat = "@" 'text
.Value = Sheets(wCtr).Name
End With
Next wCtr
End Sub
--
Jim Cone
Portland, Oregon USA




"srctr" <[email protected]>
wrote in message
I have this macro (inherited from another user) that will take all the sheet
names and put it in a list. My problem is it lists the last sheet first. I
need it skip the first sheet which is my master list and then starting with
the next sheet put them in order. Sheet1, Sheet2 etc. I know there is
something that is telling it what order to compile it, I just don't what.
Thanks,
cao

Sub WorksheetNamesList()
Dim wCtr As Long
Dim rCtr As Long
rCtr = 1
For wCtr = Worksheets.Count To 2 Step -1
rCtr = rCtr + 1
With ActiveSheet.Cells(rCtr, 1)
.NumberFormat = "@" 'text
.Value = Sheets(wCtr).Name
End With
Next wCtr
End Sub
 
To list all sheets in order, omitting the first:
Change
For wCtr = Worksheets.Count To 2 Step -1
to
For wCtr = 2 To Worksheets.Count


Here is an alternative

Sub WorksheetNamesList()
Dim wCtr
Dim rCtr As Long
rCtr = 1
For Each wCtr In Worksheets
If wCtr.Name <> "Master" Then
rCtr = rCtr + 1
With ActiveSheet.Cells(rCtr, 1)
.NumberFormat = "@" 'text
.Value = wCtr.Name
End With
End If
Next wCtr

End Sub
 
Sub simplesheetlist()
For i = 2 To Worksheets.Count
Cells(i, 1) = Sheets(i).Name
Next i
End Sub
 
Back
Top