+ Reply to Thread
Results 1 to 13 of 13

List worksheet names using a formula

  1. #1
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    List worksheet names using a formula

    I don't know if this topic has already been introduced. I tried using the search utility but all it did was "complain" about the search parameters I used.

    You can generate a list of the worksheet names using formulas. This method uses an XL4 macro function combined with worksheet functions.

    Here's how to do it:

    Create this defined name...

    In Excel versions 2007 and later:

    Goto the Formulas tab>Define Name

    In Excel versions 2003 and earlier:

    Goto the menu Insert>Name>Define

    Name: SheetNames
    Refers to: =GET.WORKBOOK(1)&T(NOW())
    OK out

    Then, to list the sheet names enter one of these formulas in cell A1:

    In Excel versions 2007 and later:

    =IFERROR(INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),ROWS(A$1:A1)),"")

    In Excel versions 2003 and earlier:

    =LOOKUP("zzzzz",CHOOSE({1,2},"",INDEX(MID(SheetNames,FIND("]",SheetNames)+1,255),ROWS(A$1:A1))))

    Copy down until you get blanks.

    Some notes:

    The &T(NOW()) is used to make the formula volatile so that it recalculates when a sheet is added/deleted or when a sheet name is changed.

    GET.WORKBOOK(1) returns the sheet names as a horizontal array.

    1 is the argument index number for returning the sheet names.

    If doing this in Excel versions 2007 and later the file must be saved as a macro enabled file in the *.xlsm file format.
    Last edited by Tony Valko; 06-10-2013 at 01:18 PM. Reason: changed some wording
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,244

    Re: List worksheet names using a formula

    Brilliant! Is it possible to tweak the formula to omit hidden sheets and/or omit, say, first and last from the generated list?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: List worksheet names using a formula

    Unfortunately, using this technique, you can not omit hidden sheets.

    You can specify which sheet name you do want by modifying this expression:

    ROWS(A$1:A1)

    As you drag copy the formula the ROWS function is used as an incrementer to tell the INDEX function which sheet name to return. The sheet names are "stored" in the INDEX function in "positions" starting from position 1 to position N (the total number of sheet names).

    Such that:

    ROWS(A$1:A1) = sheet1
    ROWS(A$1:A2) = sheet2
    ROWS(A$1:A3) = sheet3
    etc
    etc

    So, if you want to start the list with sheet2 then change ROWS(A$1:A1) to ROWS(A$1:A2).

    We could probably put something in the formula to omit the first and last sheet name by comparing the number of rows the formula is being copied to against the total number of sheets.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,244

    Re: List worksheet names using a formula

    Thanks, Tony. Food for thought!

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: List worksheet names using a formula

    You're welcome!

  6. #6
    Registered User
    Join Date
    03-05-2014
    Location
    Calabash, NC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: List worksheet names using a formula

    Excel 2007, did not work for me
    get.workbook(1) is not a valid function

  7. #7
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: List worksheet names using a formula

    You have to create the defined named formula "SheetNames".

    Here's a small sample file created in Excel 2007 that demonstrates this.

    List Sheet Names Excel 2007.xlsm

  8. #8
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: List worksheet names using a formula

    also this one.

    name: listworkbooks
    refers to=FILES(A1).

    in cell A1 you can enter a path /folder / filename or wild cards like c:\*.* -> c:\month*.xls

    =INDEX(listworkbooks,ROW()) -> start it in row 1 any column
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  9. #9
    Registered User
    Join Date
    03-05-2014
    Location
    Calabash, NC
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: List worksheet names using a formula

    thx Tony
    must have had a typo
    what I was hoping for is Workbook-A getting the worksheet names in Workbook-B

  10. #10
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: List worksheet names using a formula

    You could use the method in one workbook then just use simple link formulas in the other workbook.

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: List worksheet names using a formula

    @ vlady...

    I have a macro that does pretty much the same thing but I just tried your suggestion and it works just fine.

  12. #12
    Registered User
    Join Date
    06-13-2019
    Location
    St. Louis, Missouri
    MS-Off Ver
    Office 365
    Posts
    1

    Re: List worksheet names using a formula

    This is great however it only works dragging down in a column for the list, is it possible to make it drag across so the list is in a row instead of a column?

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: List worksheet names using a formula

    Quote Originally Posted by Keith.Hejnal View Post
    This is great however it only works dragging down in a column for the list, is it possible to make it drag across so the list is in a row instead of a column?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original. Please start a new thread - See Forum rule #4

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1