Worksheet names into Cells

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Does anyone have a code that would put the names of all worksheets to the right of sheet3, in the cells of row 1 after the last column in the last worksheet. Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try:
Code:
Sub GetSheetNames()
    Dim lColumn As Long
    Dim ws As Worksheet
    For Each ws In Sheets
        lColumn = Sheets(Sheets.Count).Cells(1, Columns.Count).End(xlToLeft).Column
        Sheets(Sheets.Count).Cells(1, lColumn + 1) = ws.Name
    Next ws
End Sub
 
Upvote 0
That works great, but it pulls all the worksheet names. Is there a way to only pull a certain range of worksheets. For example if you had 10 worksheets, you would pull the names from worksheets 4-8?
 
Upvote 0
Try:
Code:
Sub GetSheetNames()
    Dim lColumn As Long
    Dim x As Long
    For x = 4 To 8
        lColumn = Sheets(Sheets.Count).Cells(1, Columns.Count).End(xlToLeft).Column
        Sheets(Sheets.Count).Cells(1, lColumn + 1) = Sheets(x).Name
    Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
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