+ Reply to Thread
Results 1 to 5 of 5

Cumulative Array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    cape town
    MS-Off Ver
    Excel 365 Subscription
    Posts
    120

    Cumulative Array

    Hi All,

    Could someone please assist me with a corkscrew type array. I have attached a spreadsheet.

    What I am trying to achieve is a result by subtracting Table B from Table A. However, if the result in any cell is negative, then I would like the negative value to be carried forward and netted off against the next cell in the sequence until it has been extinguished (from left to right, top to bottom with the desired result shown in the Required Table).

    For instance, in cell H17 there is a -3: I would like not to show the -3 (just show a 0) but to cumulatively deduct it off the next cell in the sequence, until the negative -3 has been extinguished which happens to be the next cell H23. Similarly, cells J16 and J17 are cumulatively netted off by cell K20. The negative number in cell L15 is netted off in cell L21.

    I hope my explanation is clearer than mud!

    Any help would be appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Cumulative Array

    I can't figure out a way to do that just in a formula. Here's how it could be done with a macro:

    Option Explicit
    Public Sub SubractTest()
    
    With Sheets("Sheet1")
        SubtractArrays .Range("G3:L6"), .Range("G9:L12"), .Range("G15:L18")
    End With
    
    End Sub
    Public Sub SubtractArrays(firstArray As Range, secondArray As Range, targetArray As Range)
    
    Dim thisRow As Long
    Dim thisCol As Long
    Dim carryValue As Long
    
    carryValue = 0
    For thisCol = 1 To firstArray.Columns.Count
        For thisRow = 1 To firstArray.Rows.Count
            carryValue = carryValue + firstArray.Cells(thisRow, thisCol) - secondArray.Cells(thisRow, thisCol)
            If carryValue >= 0 Then
                targetArray.Cells(thisRow, thisCol).Value = carryValue
                carryValue = 0
            Else
                targetArray.Cells(thisRow, thisCol).Value = 0
            End If
        Next thisRow
    Next thisCol
    
    End Sub
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Forum Contributor
    Join Date
    04-02-2012
    Location
    cape town
    MS-Off Ver
    Excel 365 Subscription
    Posts
    120

    Re: Cumulative Array

    Hi WBD,

    Thank you - this is good. I appreciate the time that you have taken to help me.
    Many thanks.

  4. #4
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Cumulative Array

    Please try at G20

    =MAX(G3-G9-SUM($F$20:F$23,G$19:G19)+SUM($F$3:F$6,G$2:G2)-SUM($F$9:F$12,G$8:G8),0)

    or Spill array for MS365 Insider with LAMBDA Function

    =LET(c,SCAN(0,SCAN(0,TRANSPOSE(G3:L6-G9:L12),LAMBDA(a,v,a+v)),LAMBDA(a,v,IF(a>v,a,v))),s,SEQUENCE(ROWS(c),COLUMNS(c)),TRANSPOSE(SMALL(c,s)-IFERROR(SMALL(c,s-1),0)))
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    04-02-2012
    Location
    cape town
    MS-Off Ver
    Excel 365 Subscription
    Posts
    120

    Re: Cumulative Array

    Many thanks Bo_Ry,

    This is terrific. I don't have the insider version, so I appreciate your giving me an alternative solution.
    Thank you for the time that you have taken to help me.

+ 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. Cumulative sum with dynamic array formula
    By Marbleking in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-10-2021, 12:10 PM
  2. [SOLVED] Dynamic Array Cumulative Sum
    By moglij in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-27-2020, 05:09 AM
  3. [SOLVED] Ascendent array cumulative
    By Yaghoub61 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-09-2020, 01:25 PM
  4. [SOLVED] Convert two-dimensional array elements to cumulative sums
    By jakebryant in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 07-06-2018, 08:09 PM
  5. [SOLVED] Array formula to return all steps of cumulative / running total
    By Stormin' in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 04-03-2018, 05:18 AM
  6. Cumulative Sum of values in an array
    By seigna in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2013, 06:59 PM
  7. Replies: 6
    Last Post: 05-23-2008, 01:46 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