+ Reply to Thread
Results 1 to 12 of 12

Can I reference a worksheet by its position instead of its name?

  1. #1
    Registered User
    Join Date
    12-28-2012
    Location
    Longmont, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    5

    Can I reference a worksheet by its position instead of its name?

    I have been using Excel for years, but I have just started a project where, for the first time, I am using multiple worksheets. The first worksheet is named "Summary." The rest of the worksheets are named for companies that I receive payments from (4 or 5 different companies). If I create a new company worksheet, I will manually sort the tabs into alphabetical order (except for the summary which will alway be first). In cell A1 of each sheet I will be copying the name of that worksheet from the tab below. All of this I can do with no problem.

    On the summary page, I want to put the names of the companies in Column A with one company on each line. These names will appear starting on row 4 with name from the second tab, row 5 with name from third tab, etc. I can get this info from either the name of the tab or from cell A1 on that worksheet which will be the same name.

    Problem: I can't figure out how to reference the tabs by their position so that the names will be sorted in the same order on the summary worksheet as are the worksheet tabs. Is there a way to do this? I do not know VB or how to implement it. I am hoping there is a way to do this just using Excel keywords.

    Any help greatly appreciated!

  2. #2
    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
    53,049

    Re: Can I reference a worksheet by its position instead of its name?

    try high-lighting all the tab names on the summary sheet and then sort them
    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

  3. #3
    Registered User
    Join Date
    12-28-2012
    Location
    Longmont, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Can I reference a worksheet by its position instead of its name?

    I will be pulling in a lot of column totals from the various company pages as well. If I can't reference the worksheets by their position, I would have to hard code all the names into the various cells. There will also be additions and deletions from the companies from time to time. I am trying to set it up so that the only manual action I will have to take is to sort the tabs and change the names on the tabs. It may be that what I am trying to do is not possible without using VB or similar.

    Thanks for your reply.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Can I reference a worksheet by its position instead of its name?

    Hi jrwitt,

    Here's sheet sort that leaves the first sheet in place:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Registered User
    Join Date
    12-28-2012
    Location
    Longmont, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Can I reference a worksheet by its position instead of its name?

    Obviously I did not make the problem clear. Sorting is not a problem. The problem is that I need to pull data from the various worksheets based on their position in the tabs at the bottom of the workbook. When I complete the spreadsheet, I will be pulling data from several different cells on each sheet. I don't want to hardcode the names into each cell formula.

    I need a way to reference the cell by its position in the tab list. Is this possible in Excel?

  6. #6
    Registered User
    Join Date
    12-28-2012
    Location
    Longmont, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Can I reference a worksheet by its position instead of its name?

    Obviously I didn't make it clear what i am looking for. Sorting the names is not a problem. I need to get several items of data from each sheet and place it on the summary sheet. I don't want to hard code the name on the tab in all the cells that I am pulling data into. The names of the tabs will change from time to time. I just want a way to get a value from a particular cell on the 2nd (or 3rd, etc.) sheet. I need something like =(sheet(3), Cell(C4)).

    Is it possible to reference a worksheet by its position in the list at the bottom of the spreadsheet?

  7. #7
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Can I reference a worksheet by its position instead of its name?

    Excel does not have a formula to reference the sheets in such a way.
    A custom function could be written if VBA is an option for you.
    Last edited by Palmetto; 12-29-2012 at 09:20 AM.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Can I reference a worksheet by its position instead of its name?

    If its every sheet then you should just use the For Each...Next construct - if they're in the same place or can be found automatically!
    Last edited by xladept; 12-29-2012 at 02:10 AM.

  9. #9
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Can I reference a worksheet by its position instead of its name?

    Maybe it's better if you explain what you want to achieve, instead of what you want to do.

    Maybe you can pull all the data (with VBA) in 1 sheet and after that use excelfunctions for your task.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  10. #10
    Valued Forum Contributor
    Join Date
    07-29-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003/Excel 2010
    Posts
    534

    Re: Can I reference a worksheet by its position instead of its name?

    See attachment to check if this is usefull to you.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Can I reference a worksheet by its position instead of its name?

    What you want can be done, but the process is a little convoluted.

    First you create a named range that will generate an array of sheet names, for example,

    Name:- SheetList
    Refers to:- =GET.WORKBOOK(1,"Book1.xlsm")

    Now you have an array of sheet names to work with, you can use thgis to generate indirect references in your summary sheet.

    =INDEX(SheetList,1) will return the name of the summary sheet as this is in position 1, to make it useful, you would need to convert it to a valid range using indirect. The ROWS() counter used below will start the array at sheet2.

    =INDIRECT("'"&INDEX(SheetList,ROWS($A$2:$A2)+1)&"'!A1")

    You will need to save your workbook as Macro Enabled.

    Does this give you something you can work with?

  12. #12
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,378

    Re: Can I reference a worksheet by its position instead of its name?

    Hi,

    In VBA the worksheets have an Index number based on where they are from left to right. In your VBA Immediate window put this code:

    Debug.Print Worksheets(1).Name and press enter. The name of the first worksheet tab should be displayed in the immediate window. If you replace the 1 with a 2 or 3 or 4 the name of increasing tabs will appear.

    To work through all your worksheets you need to find how many there are and that would be "Worksheets.Count" in VBA code.

    See if http://msdn.microsoft.com/en-us/libr...ffice.11).aspx helps explain it better.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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