+ Reply to Thread
Results 1 to 6 of 6

Incorporate the INDIRECT function correctly into a formula

  1. #1
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Incorporate the INDIRECT function correctly into a formula

    Hi,

    It's been a while since I've been on here but it's good to be back! And I thought I would start by asking for help with the below, to make things simple I have made my formulas generic just incase anyone else would find this solution useful.

    I have a formula to sum the values across several sheets, =SUM('1:100'!A1), and it does the job as expected adding all values in A1 across the sheets in that range.
    I would like to replace the 1 and 100 so it uses values from two cells, lets say these are located on a sheet called DATA and the first cell is A1 and the second is A2.

    I've tried my best to get this to work with the INDIRECT function but it just doesn't want to work for me! I've attepted this using the 2 ways below:

    =SUM(INDIRECT("'"&DATA!A1&":"&DATA!A2&"'!A1")) creating a range using INDIRECT within the SUM function
    =INDIRECT("SUM('"&DATA!A1&":"&DATA!A2&"'!A1)") using everything within the INDIRECT function

    I know I've propably missed something simple but I can't for the life of me figure it out.

    As always thanks for your help,
    Harribone


    EDIT
    I have also tried creating a text string in a cell to generate the range to sum and then using the INDIRECT function referencing that cell. That hasn't worked so I think this might not be sommething that can be done...
    Last edited by Harribone; 02-21-2014 at 06:10 PM. Reason: See EDIT section of post
    Say thanks, click *

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Incorporate the INDIRECT function correctly into a formula

    if sheet names are realy just numbers wher k1 and l1 hold the numbers i couldn't get it to work with sum but sumif works
    =SUMPRODUCT(SUMIF(INDIRECT(ROW(INDIRECT($K$1&":"&$L$1))&"!a1"),"<>"))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Re: Incorporate the INDIRECT function correctly into a formula

    Thanks for your work on this, i've never used sumproduct before so hadn't considered this approach at all.
    After testing it does do the job but only when the sheets follow on from each other. So if I had sheets 1, 2 and 3 this would be grand but if I have sheets 1,3 and 500 it causes a #REF error. I didn't mention that the sheet numbers would be random (still in order smalest to largest though) as the basic formula works and I assumed the solution would work in the same way.

    Appriciate the time taken though to get as far as you have with a better solution than I managed.

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

    Re: Incorporate the INDIRECT function correctly into a formula

    If the number of sheets to include in the calculation varies create a dynamic range that refers to the sheet names.

    Data Range
    A
    B
    1
    Sheets
    Sum
    2
    1
    22514
    3
    3
    4
    4
    5
    6
    7
    8
    9
    10


    Let's assume the sheet names will be in the range A2:A10 but the number of sheets varies.

    Create this dynamic range:

    Name: Sheets
    Refers to: =$A$2:INDEX($A$2:$A$10,MATCH(1E100,$A$2:$A$10))

    Then, the sum formula becomes:

    =SUMPRODUCT(N(INDIRECT(Sheets&"!A1")))

    Note that the sheet names must be entered in a contiguous range but can also be entered in any order.
    Last edited by Tony Valko; 02-21-2014 at 10:06 PM.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  5. #5
    Valued Forum Contributor Harribone's Avatar
    Join Date
    02-24-2013
    Location
    Midlands, UK
    MS-Off Ver
    Excel 2019/365
    Posts
    570

    Re: Incorporate the INDIRECT function correctly into a formula

    Thanks for this I will give it a go to see if this will work for my data, just so I understand though what is the N() function doing?
    Never used it before and it looks like it is similar to VALUE()? Always looking to expand my knowledge, rather learn the function than just accept it.


    EDIT
    Tried and tested this. Does the job I need perfectly.
    This will save people at work creating a long winded =Sheet1!A1+Sheet2!A1.... style formula which is annoying to edit when sheets are added removed. Plus it looks messy.
    Last edited by Harribone; 02-22-2014 at 03:47 PM.

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

    Re: Incorporate the INDIRECT function correctly into a formula

    Quote Originally Posted by Harribone View Post
    what is the N() function doing? ...it looks like it is similar to VALUE()?
    Yes, similar but not exactly the same.

    N(...) returns the numeric value of its argument. However, if the argument is a text entry N(...) returns 0 where VALUE(...) returns the #VALUE! error. We need the N(...) function in this application to convert the results of the INDIRECT function into numeric numbers.

    Tried and tested this. Does the job I need perfectly.
    Good deal. Thanks for the feedback!

+ 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. VBA to get time period, incorporate function & copy formula
    By Navin Agrawal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2013, 07:39 AM
  2. [SOLVED] INDIRECT Query: How to incorporate INDIRECT to choose between two ranges?
    By The_Snook in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-18-2012, 06:28 AM
  3. How to incorporate an if then else function to a sum formula
    By novice2430 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-01-2012, 01:06 AM
  4. Incorporate the Indirect Formula
    By mcmuney in forum Excel General
    Replies: 2
    Last Post: 10-16-2010, 04:44 AM
  5. how to incorporate an if then else function to an average formula
    By novice2430 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-17-2009, 02:15 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