Worksheet List In Another Window

FRIJOE

New Member
Joined
May 4, 2017
Messages
19
Hello,

I want to have a list of all the worksheets in my workbook listed on another sheet.

Right now I have;

Sub SheetNames()
Dim wsheet As Worksheet

Set wsheet = Worksheets("Lists")
With ws
Columns(1).Insert
For i = 1 To Sheets.Count
Cells(i, 1) = Sheets(i).Name
Next i
End With
End Sub

I am trying to have the list populate on sheet name "Lists", however whenever I run the code, the output is on whatever page is currently open when I run it.

Any help?

Thank you,
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You need to put a . (period) in front of Cells(i,1)
 
Last edited:
Upvote 0
Try this:
Code:
Sub Add_Sheets_Names()
'Modified 3-19-18 5:25 PM EDT
Dim i As Long
    For i = 1 To Sheets.Count
        Sheets("Lists").Cells(i, 1).Value = Sheets(i).Name
    Next
End Sub
 
Upvote 0
Disregard my last, you are correct. The fourth line of my code used a different and undefined variable "ws"

I edited it and now have this;

Sub SheetNames()
Dim ws As Worksheet

Set ws = Worksheets("Lists")
With ws
.Range("a1:a50").Clear
For i = 1 To Sheets.Count
.Cells(i, 1) = Sheets(i).Name
Next i
End With
End Sub

Which is working perfectly.

Thank you!
 
Upvote 0
@FRIJOE
your original code should be
Code:
Sub SheetNames()
Dim wsheet As Worksheet

Set wsheet = Worksheets("Lists")
With wsheet
   .Columns(1).Insert
   For i = 1 To Sheets.Count
   .Cells(i, 1) = Sheets(i).Name
   Next i
End With
End Sub
I missed that you had changed wsheet to ws.

EDIT
I see that you've sorted.

Glad to help & thanks for the feedback
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top