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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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