Retrieve the name of worksheets in a workbook to a specific cell!!!!!!

Mark McInerney

Active Member
Joined
Apr 4, 2012
Messages
259
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have 52 sheets, and I want to run a macro that I found online to retrieve the name of all the worksheets and place them in a specific row or column (not fussy - just need the data).

I found this, and press ALT +F11, paste it into the immediate pane, but nothing happens??

Am I doing something wrong - is there an easier way of retrieving the info that I am looking for?? Any Help - Appreciated. Thanks - Mark.

Sub ListSheetNames()
*** Dim R As Range
*** Dim WS As Worksheet
*** Set R = ActiveCell
*** For Each WS In ThisWorkbook.Worksheets
******* R.Value = WS.Name
******* Set R = R(2, 1)
*** Next WS
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi,

Not sure about the Immediate window, but if you paste the code into a new Module and click run (F5) it should work.

Code:
Sub ListSheetNames()
    Dim R As Range
    Dim WS As Worksheet
    Set R = ActiveCell
    For Each WS In ThisWorkbook.Worksheets
        R.Value = WS.Name
        Set R = R(2, 1)
    Next WS
End Sub
 
Upvote 0
Hi Rick,

Thanks for coming back to me on this - appreciated. Silly Question.....how do I create a new module??

Thanks - Mark.


Hi,

Not sure about the Immediate window, but if you paste the code into a new Module and click run (F5) it should work.

Code:
Sub ListSheetNames()
    Dim R As Range
    Dim WS As Worksheet
    Set R = ActiveCell
    For Each WS In ThisWorkbook.Worksheets
        R.Value = WS.Name
        Set R = R(2, 1)
    Next WS
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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