+ Reply to Thread
Results 1 to 13 of 13

Reference worksheet in a formula

  1. #1
    Registered User
    Join Date
    12-22-2014
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    89

    Reference worksheet in a formula

    Hi,

    Just wondering if its possible to keep the reference worksheet in a formula even if it doesnt exist?

    I am trying to run a report from a sheet which will be generated only after a macro runs. So before the macro runs that refernce worksheet doesnt exist.

    Thanks

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

    Re: Reference worksheet in a formula

    Try wrapping the formula inside an IFERROR function:

    =IFERROR(your formula here,"")
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Registered User
    Join Date
    12-22-2014
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    89

    Re: Reference worksheet in a formula

    Hi,
    It doesnt work.

    Once the sheet where the formula is referencing is deleted the formula goes bad.

    any other ideas??

  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,916

    Re: Reference worksheet in a formula

    What do you mean by "goes bad"? Do you mean that you get the #Ref! error?
    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.

  5. #5
    Registered User
    Join Date
    12-22-2014
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    89

    Re: Reference worksheet in a formula

    Yes #ref error

  6. #6
    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,916

    Re: Reference worksheet in a formula

    Instead of deleting worksheets, can you just hide them? How about giving us an example of a formula that gives the error if a worksheet is deleted. Why do your need the reference if the worksheet is deleted, anyway? It may be something to do with your work-flow that we can help you with here.

    EDIT: I have just read your opening post again and understand a bit better now. I am wondering if you perhaps need to use the INDIRECT function to reference the worksheet.
    Last edited by AliGW; 10-15-2016 at 07:42 AM.

  7. #7
    Registered User
    Join Date
    12-22-2014
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    89

    Re: Reference worksheet in a formula

    Hi,

    See attached file.
    Sheet Data has original data.
    Then using a macro I am generating Output sheet everytime I populate new data.
    Then I want to run a report from output sheet
    Attached Files Attached Files

  8. #8
    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,916

    Re: Reference worksheet in a formula

    The error is showing. Please paste here the formula you are trying to use.

    Here's an example:

    =INDIRECT("'"&G1&"'!A1")

    returns the contents of cell A1 on the Output sheet. G1 is on the main sheet containing the formula somewhere (could be a cell in a hidden column or row) and contains the word Output.

  9. #9
    Registered User
    Join Date
    12-22-2014
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    89

    Re: Reference worksheet in a formula

    =SUMIFS(Output!$Q:$Q,Output!$N:$N,Report!B1,Output!$K:$K,Report!A2)

  10. #10
    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,916

    Re: Reference worksheet in a formula

    So try this:

    =SUMIFS(indirect(G1&"!$Q:$Q"),indirect(G1&"!$N:$N"),Report!B1,indirect(G1&"!$K:$K"),Report!A2)

    where G1 is the cell containing the word Output.

  11. #11
    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,916

    Re: Reference worksheet in a formula

    The other option is to change your macro so that, instead of creating the sheet, it empties and replaces the sheet's contents, leaving the sheet itself intact.

  12. #12
    Registered User
    Join Date
    12-22-2014
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    89

    Re: Reference worksheet in a formula

    Thanks works perfect

    Awesome

  13. #13
    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,916

    Re: Reference worksheet in a formula

    You're welcome!

+ 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. Formula to reference the name of a worksheet other than the one being used
    By STUARTXL in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-10-2016, 05:27 AM
  2. how do i reference a worksheet variable in a formula?
    By chemeng1T3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2012, 08:27 AM
  3. Replies: 5
    Last Post: 02-06-2012, 12:36 PM
  4. [SOLVED] Reference Worksheet Name variable in VBA formula
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2006, 03:05 PM
  5. [SOLVED] reference current worksheet name (tab name) in a formula
    By Janet Panighetti in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-03-2006, 05:35 PM
  6. two worksheet reference formula help
    By chadhart in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-02-2006, 06:50 PM
  7. Worksheet name / reference as a formula?
    By gabriel_e in forum Excel General
    Replies: 4
    Last Post: 01-24-2006, 08:25 AM

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