+ Reply to Thread
Results 1 to 4 of 4

How to sum variable cell range withing array?

  1. #1
    Registered User
    Join Date
    01-30-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    3

    How to sum variable cell range withing array?

    Hi everyone, here is the issue



    I have a range of future annual income in a row. Starting in 2011, ending in 2100.

    I want to sum the cumulative incomes in a new row.

    However this should only hold true for fixed-year periods, say 20.


    In 2014 the cumulative income is 2011income+2012income+2013income+2014income.

    In 2020 the sum is 2015+...+2020, in 2040 however it has to be 2020+...+2040, etc

    in other words what happened more than 20 years ago (or any fixed period) should not be included in the cumulative income

    Along with the fixed-year periods, the starting and end years are also variable, and are given a name.

    There has to be a simple function to do this, which can be written on the first cell and then dragged it along.

    Example attached



    Thanking you very much in adavnace for your effort and help
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    01-25-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    434

    Re: How to sum variable cell range withing array?

    hmm

    I did it a different way....

    A B C forumula for column C
    17 Cummulate Income for selection
    18 Year 2012
    19 Number of Years to go back 0
    20 Income by year's investment 267 =SUM(OFFSET(C2,0,MATCH($C$18,$C$1:$CN$1,0)-1):OFFSET(INDIRECT(ADDRESS(ROW()-18,MATCH($C$18,$C$1:$CN$1,0)+2)),0,-IF($C$19>MATCH($C$18,$C$1:$CN$1,0)+1,MATCH($C$18,$C$1:$CN$1,0),$C$19)))
    21 Income by year's investment SFH 147 =SUM(OFFSET(C3,0,MATCH($C$18,$C$1:$CN$1,0)-1):OFFSET(INDIRECT(ADDRESS(ROW()-18,MATCH($C$18,$C$1:$CN$1,0)+2)),0,-IF($C$19>MATCH($C$18,$C$1:$CN$1,0)+1,MATCH($C$18,$C$1:$CN$1,0),$C$19)))
    22 Income by year's investment MFH 78 =SUM(OFFSET(C4,0,MATCH($C$18,$C$1:$CN$1,0)-1):OFFSET(INDIRECT(ADDRESS(ROW()-18,MATCH($C$18,$C$1:$CN$1,0)+2)),0,-IF($C$19>MATCH($C$18,$C$1:$CN$1,0)+1,MATCH($C$18,$C$1:$CN$1,0),$C$19)))
    23 Income by year's investment PnR 3 =SUM(OFFSET(C5,0,MATCH($C$18,$C$1:$CN$1,0)-1):OFFSET(INDIRECT(ADDRESS(ROW()-18,MATCH($C$18,$C$1:$CN$1,0)+2)),0,-IF($C$19>MATCH($C$18,$C$1:$CN$1,0)+1,MATCH($C$18,$C$1:$CN$1,0),$C$19)))
    24 Income by year's investment - nPnR 39 '=SUM(OFFSET(C6,0,MATCH($C$18,$C$1:$CN$1,0)-1):OFFSET(INDIRECT(ADDRESS(ROW()-18,MATCH($C$18,$C$1:$CN$1,0)+2)),0,-IF($C$19>MATCH($C$18,$C$1:$CN$1,0)+1,MATCH($C$18,$C$1:$CN$1,0),$C$19)))

    This method lets you enter a year into Cell C18
    Enter how many years to go back in cell C19 (zero years to view only the selected year)
    If you enter 10, it will actually be giving results of 11 years, because it's going back 10 years and also including the year you selected, so if you want exactly 10 years worth of values then you should enter 9

    In the rows below it will give you the cumulative results

    Just copy and paste from the table above the formula for cell C20, you can then just copy and paste it down on the sheet
    There's no need to paste the formulas in other columns, it's giving you all the answers you want in just the one column

    If this solution isn't any good to you at all, then let me know and I'll see if I can re-work it

    In your example file you didn't have anywhere to enter variables such as how many years to go back, which is why I just came up with the method I did. It might be worth you changing the example file to show exactly how you want the results to be displayed

    example - ThirtyTwo.xlsx
    Last edited by ThirtyTwo; 01-30-2014 at 12:15 PM.

  3. #3
    Registered User
    Join Date
    01-30-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to sum variable cell range withing array?

    hi ThirtyTwo

    that was a quick reply!

    your method can indeed provide the desired outcome for the given year!

    What I need however is to populate the row for all years (not just for one year) and have the whole timeseries visible.

    I got this based on your equations by simply pointing the 'year' value to the the first row with years and replacing the start of the sum values in the following way:

    =SUM(C2:OFFSET(C2,0,-IF($B$19>MATCH(C1,$C$1:$CN$1,0)+1,MATCH(C1,$C$1:$CN$1,0),$B$19)))




    Thanks you very much!
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    01-25-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    434

    Re: How to sum variable cell range withing array?

    Sorry for the delay in responded back to your post, been away working

    I'm pleased you managed to salvage something from the formula I made, seems like the new sheet you created is giving you exactly what you were looking for, very impressed with how you adjusted that lengthy formula to make it work for all 90 years worth of data

    Just noticed something you could change in the formula you created

    change - MATCH(C1 to MATCH(C$1

    This would have allowed you to copy the formula down and across without having to make the manual adjustments you did on each row in column C before copying and pasting across all columns, $1 would keep that row number fixed when you copy it down




    If your question is resolved, mark it SOLVED using the thread tools
    Click on the star (Add Reputation) if you think someone helped you with the information supplied in their post
    Last edited by ThirtyTwo; 01-31-2014 at 09:56 PM.

+ 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. Find a string withing cell range and return cell number
    By visak in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-16-2015, 09:19 PM
  2. Selecting cells withing a date range
    By v7e8n3e1z2u8e5l in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 06:27 AM
  3. vlookup with variable range and variable array size
    By chaslie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2013, 02:37 PM
  4. Storing VB Code in a variable withing a Macro
    By reclmaples in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-02-2009, 11:45 AM
  5. Messages box as warning for changes withing a range
    By mikeyfear in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-23-2008, 03:00 AM

Tags for this Thread

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