Retreiving last 6 Sheet names in different rows

Firasath

Board Regular
Joined
Feb 20, 2011
Messages
137
Office Version
  1. 365
Hi,

I want to put previous 6 months' Sheet Names in last sheet of workbook. Sheet names are in MMM-YY format and each month new sheet would be added with new months data.

The requirement is to put each sheet names either in separate rows or in separate columns.

Can somebody please advise a way to accomplish so.

Regards.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Assuming that your tabs are in order then the below will list the names from the previous 6 sheets in cell A2 down of the last sheet.

Code:
Sub GetShtName()
    Dim i As Long, x As Long
    x = 2
    For i = Worksheets.Count - 6 To Worksheets.Count - 1
        Worksheets(Worksheets.Count).Cells(x, 1) = Worksheets(i).Name
        x = x + 1
    Next
End Sub
 
Upvote 0
Assuming that your tabs are in order then the below will list the names from the previous 6 sheets in cell A2 down of the last sheet.

Code:
Sub GetShtName()
    Dim i As Long, x As Long
    x = 2
    For i = Worksheets.Count - 6 To Worksheets.Count - 1
        Worksheets(Worksheets.Count).Cells(x, 1) = Worksheets(i).Name
        x = x + 1
    Next
End Sub

Thanks Mark. It worked and pasted the results in last sheet. Is it possible to provide the specific sheet name and cell reference where the results are pasted.
 
Upvote 0
Or is it possible to create six functions for six previous sheets to get the sheet names in any cell.
 
Upvote 0
Explain exactly where you want the results to end up.
 
Upvote 0
Explain exactly where you want the results to end up.

Dear Mark,

Let me try to articulate clearly my requirement. I want to place this info in different locations in a sheet called "Summary". I have used six functions, one function for each sheet, to retrieve data from previous six sheets. For your reference, I am putting the code for that below. I want something similar to place the sheet names. With these functions, I can use it as formula and refer a cell to retrieve the data from previous sheets.

Or else can we edit the above code provided by you to specify the sheet name "Summary" to place the data instead of last sheet of the workbook.

Code:
Function PrevSheet6(RCell As Range)
    Dim xIndex As Long
    Application.Volatile
    xIndex = RCell.Worksheet.Index
    If xIndex > 1 Then _
        PrevSheet6 = Worksheets(xIndex - 6).Range(RCell.Address)
End Function
 
Upvote 0
I want to place this info in different locations in a sheet called "Summary"

But you haven't stated what the different locations are... I am going to work now and so will look at this tomorrow if no-one picks up on it.

P.S. if you wanted it in a sheet called "Summary" then you should have stated it in the first post rather than
I want to put previous 6 months' Sheet Names in last sheet of workbook.
 
Upvote 0
But you haven't stated what the different locations are... I am going to work now and so will look at this tomorrow if no-one picks up on it.

P.S. if you wanted it in a sheet called "Summary" then you should have stated it in the first post rather than

My apologies please as I was little bit confused related to the outcome of the results.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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