Cumulative Total Example
description
Transcript of Cumulative Total Example
Item No. No. Worked On TOTAL
3B Item 13G Item 26A Item 36C Item 46D Item 526A Item 624A Item 76G Item 8
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).1down votefavorite
Sub cum(ByVal DataPoints As Long)Application.ScreenUpdating = FalseDim index As LongDim runningCum As Long
runningCum = 0
For index = 3 To DataPoints'Set cell to Cum Oil column at index row cel = Cells(index, "K") 'If the well name in previous row is equal to well name in index row, add oil values to runningCum If Cells(index - 1, "D") = Cells(index, "D") Then runningCum = runningCum + Cells(index, "F") + Cells(index, "H") 'Otherwise, reset runningCum Else runningCum = 0 End If 'Set the Cum Oil cell value to the runningCum cel = runningCumNext
Application.ScreenUpdating = TrueEnd Sub
share|improve this questionuser3204211
82add comment
1 Answeractiveoldestvotesup vote1down voteaccepted
0
but if you prefer VBA, try to change in your code:
or you can use following simple code (it calculates values using formulas, and then deletes formulas and leaves only values):
Sub cum(ByVal DataPoints As Long)
With Range("K3:K" & DataPoints) .Formula = "=IF(D2=D3,K2+F3+H3,0)" .Calculate
excel vba excel-vbaasked Jan 16 at 20:51
You can use very simple formula in K3 and stretch it down:
cel = Cells(index, "K") to Set cel = Cells(index, "K")
and cel= runningCum to cel.Value = runningCum
.Value = .Value End WithEnd Sub
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).
or you can use following simple code (it calculates values using formulas, and then deletes formulas and leaves only values):
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).
Hello I have been stuck on my first subroutine for a while now and have tried researching my problem but am fairly new to VBA so have had little luck finding anything specific. I have a rather large spreadsheet (56090 rows) which is full of daily data points for a bunch of items with unique names. The item name is located in column D and the data I need is located in columns F and H. I am trying to create a cumulative sum for each day in column K that resets when it reaches a new item name (by checking the current row item name with the previous row item name). The code I have seems to do the trick but stops running at row 22510 (no error, just the sum values after this row are wrong).