+ Reply to Thread
Results 1 to 3 of 3

Best way to fiigure out the proper sheet to reference cells in a different workbook

  1. #1
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    403

    Best way to fiigure out the proper sheet to reference cells in a different workbook

    Greetings,

    I'm fond of referencing cells in sheets by using the sheet's CodeName whenever possible. This method is preferable to me because the user, at some point in the future, might rename the sheet. For example, I don't want to refer to the "Summary" tab specifically by that name, because it might not always be named "Summary."

    I also don't wish to refer to the sheet's index, since the user might also add or remove sheets at some point. And I've learned that referencing the sheet by its CodeName solves these problems.

    However, I just recently learned you can't reference a sheet by its CodeName if the sheet is in a different workbook than the one in which the code resides. And sure enough, all of the attempts I've tried to do just that have failed. So, in that case, what's the best way to find/reference a particular sheet?

    For example, I'm attempting to reference a sheet in another workbook. The data I want is currently on the sheet that has a CodeName of Sheet9. The user's workbook tab name is called "Summary" and right now it happens to be the 17th sheet in the other workbook. In my program this works:

    data$ = wb.Worksheets(18).Cells(1, 1)

    and this works too:

    data$ = wb.Worksheets("Summary").Cells(1, 1)

    But as mentioned above, I'd rather not user "Summary" or use the index. So what's the preferred method for something like this? (The only thing I can think of is to loop through all of the sheets, looking for something specific that I expect to find on this sheet and this sheet alone, and once I find it then I will know THAT's the sheet I want.)

    As always, thanks in advance for your reply.

  2. #2
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Best way to fiigure out the proper sheet to reference cells in a different workbook

    Hi Ed.. This is how I do it
    Put an empty workbook named TESTER.xlsx in your downloads folder to test this code. Then copy & paste the code below into an empty module & play with it.
    Please Login or Register  to view this content.
    Hope it's of use
    Phil

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Best way to fiigure out the proper sheet to reference cells in a different workbook

    You stated every possibilities neatly and I don't think there is any other go


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Locked formula changes reference when rows added to reference sheet in same workbook
    By macrorookie in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-19-2014, 04:08 PM
  2. Replies: 0
    Last Post: 06-01-2013, 05:04 AM
  3. [SOLVED] Please help me find the proper way to look-up / reference cells in separate XLSX files
    By Epst13n in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-25-2012, 07:29 AM
  4. [SOLVED] copy active sheet, create new workbook, name new workbook based on cell reference
    By jm0392 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2012, 07:12 PM
  5. UDF not returning proper value - circular reference/multi workbook
    By Jeff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2006, 08:55 PM

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