+ Reply to Thread
Results 1 to 14 of 14

sum numbers over several sheets with varing starting / ending point

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2016
    Location
    Bern, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    15

    sum numbers over several sheets with varing starting / ending point

    Hi there (first post, please be lenient),

    In every sheet (Sheet1, Sheet2, Sheet3) I have one value in cell B2. I add these B2's like this:
    =SUM(Sheet1:Sheet3!B2)
    Now, the names of the Sheets can vary and sometimes I only want to sum from Sheet1 to Sheet2.

    Therefore I write in cell A1 the name of the first sheet where I want to start summing and in A2 the name of the last sheet. Like this:
    A1 = "Sheet1"
    A2= "Sheet3"
    Now I try to sum again using indirect formula:
    =SUM(INDIRECT(A1&":"&A2&"!B2"))  ----> now I get #REF
    Can anybody tell me where's my mistake? Thank you so much!

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: sum numbers over several sheets with varing starting / ending point

    Are your entries in A1 and A2 spelt EXACTLY the same as the names themselves (no leading or trailing spaces in any of them)?

    If your real names contain spaces or other special characters, then you will need to include apostrophes around the names in the INDIRECT function (and there is no harm in putting them in there, anyway).

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    03-24-2016
    Location
    Bern, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    15

    Re: sum numbers over several sheets with varing starting / ending point

    Thanks Pete

    So you mean:
    SUM(INDIRECT("A1"&":"&"A2"&"!B2"))
    Unfortunately, this doesn't work. The real sheet names have characters like "ü" and "_". But it's not even working with the above example "Sheet1", "Sheet2" that have no special characters.

    hänschendampf

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: sum numbers over several sheets with varing starting / ending point

    No, I didn't mean that - an apostrophe is a single quote ( ' ) and should be placed around sheet names in formulae if you have spaces in them.

    However, I've just tried it in a mock-up and it doesn't work for me either. Perhaps INDIRECT is not able to work with multi-sheet references.

    Pete

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,938

    Re: sum numbers over several sheets with varing starting / ending point

    This seems a rather obtuse way to do things but try:
    =SUMPRODUCT(SUMIF(INDIRECT("'"&A1:A2&"'!B2"),"<>"&""))
    Let me know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  6. #6
    Registered User
    Join Date
    03-24-2016
    Location
    Bern, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    15

    Re: sum numbers over several sheets with varing starting / ending point

    Thanks JeteMc

    This works for me! But actually I don't understand anything in your formula. Would you mind writing a few words? That would be great. Thanks

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,938

    Re: sum numbers over several sheets with varing starting / ending point

    Quote Originally Posted by hänschendampf View Post
    I don't understand anything in your formula. Would you mind writing a few words?
    The indirect provides the array as we would expect, i.e. Sheet1:Sheet2!B2. I really would think this could be passed directly to the sum function, but unfortunately it didn't work. If we try to pass it directly to the Sumproduct function it yields zero. So the Sumif makes an array of values IF they are not blank spaces, then the sumproduct adds the values values in the array. If you watch this work using evaluate formula you'll see that it causes two #Value's just before passing the array sumproduct, yet yields a correct value in the end. Like I said "Obtuse", but glad that it works in your case. By the way, Welcome to the forum.
    Let me know if you have any questions.

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: sum numbers over several sheets with varing starting / ending point

    @JeteMc
    I tried your formula but I found what I think is a problem. The value returned is the sum of the value in the first worksheet and the last worksheet but omits any worksheets in between.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,938

    Re: sum numbers over several sheets with varing starting / ending point

    Quote Originally Posted by newdoverman View Post
    The value returned is the sum of the value in the first worksheet and the last worksheet but omits any worksheets in between.
    Your right, back to the drawing board.

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,938

    Re: sum numbers over several sheets with varing starting / ending point

    I am sure this is not a satisfactory solution, at least to me, however not considering VBA it is what I have found. Create two dummy sheets named First and Last. Place "First" in front of the first sheet that you want included in the SUM and "Last" after the last sheet that you want included. Lets say that you want to sum cell B2 from sheets 3 through 10, place First between sheets 2 and 3, place Last between sheets 10 and 11.
    Your formula will always be
    =SUM(First:Last!B2)
    Let me know if you have any questions.

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,418

    Re: sum numbers over several sheets with varing starting / ending point

    Quote Originally Posted by JeteMc View Post
    I am sure this is not a satisfactory solution...
    I've suggested that approach several times in the past, so I'm sure it is satisfactory. Another advantage is that you can just drag sheet tabs into the space between the First and Last sheet (or drag them out) in order to model different scenarios, and so they don't have to be in any particular order.

    Pete

  12. #12
    Registered User
    Join Date
    03-24-2016
    Location
    Bern, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    15

    Re: sum numbers over several sheets with varing starting / ending point

    @JeteMc: Thank you, this is the way I will handle things. It's not very beautiful but it'll work fine for me.

    @WHER: That is a nice solution. Since other people will add Sheets from time to time, I think it's not really suitable. But I will keep that one in mind :-) Thanks

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

    Re: sum numbers over several sheets with varing starting / ending point

    See this thread: http://www.excelforum.com/excel-form...-function.html
    Adapt this formula to your layout, also see attachment.
    =SUMPRODUCT(SUMIF(INDIRECT("'"&INDEX(A6:A10;MATCH(A2;A6:A10;0)):INDEX(A6:A10;MATCH(B2;A6:A10;0))&"'!A1:A15");">0"))
    Attached Files Attached Files

  14. #14
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,938

    Re: sum numbers over several sheets with varing starting / ending point

    You're Welcome and thank you for the feedback. If you haven't already please take a moment to mark the thread 'Solved' using the thread tools link above your first post. I hope that you have a good day.

+ 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. starting and ending month to fill same qty inbetween months
    By cpramesh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-09-2014, 03:20 AM
  2. Macro for copying - starting and ending based on value in row
    By rexer231 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 10:29 AM
  3. [SOLVED] Adding filter to all sheets with variable starting point
    By SeaniGeld in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 04:20 AM
  4. Index/Match to find Starting Point of Average, Ending Point of Average Variable
    By tgentry in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-09-2012, 01:04 AM
  5. [SOLVED] How to find Starting value and Ending Value of the product
    By svenkata in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-27-2012, 02:27 PM
  6. Replies: 2
    Last Post: 06-27-2011, 10:47 PM
  7. Charts with setting starting and ending point on x (time)
    By yuri in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 07-24-2008, 08:28 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