Hello,
from my perspective this can be done only by using macros, which are assigned to events.
- one macro storing initial values on opening the document (e.g.
EventDocOpen()
in example file assigned to event Open Document)
- one macro calculating the new value in the cell designed to hold the “Accumulated Value” (e.g.
EventSheetChanged()
in example file assigned to sheet event Content changed)
Here is the sample file: AccumulatingValue.ods
Here are the macros:
Global CurValAccum
Global CurValInput
Sub EventSheetChanged()
Dim NewValInput
Dim NewValAccum
NewValInput = ThisComponent.Sheets(0).getCellRangeByName("A2").Value
If NewValInput <> CurValInput Then
CurValInput = NewValInput
CurValAccum = CurValAccum + NewValInput
ThisComponent.Sheets(0).getCellRangeByName("B2").Value = CurValAccum
End If
End Sub
Sub EventDocOpen()
CurValInput = ThisComponent.Sheets(0).getCellRangeByName("A2").Value
CurValAccum = ThisComponent.Sheets(0).getCellRangeByName("B2").Value
End Sub
Notes
- The sample file is an outline only and not a solution (the macros lack any error handling, input type checking or some such)
- The macros work only for cell
A2
(Input Value) and B2
(Accumulated Value) - The cell names are hard coded.
- There is no reset function (hence if you want to start over, you need to set
0
into B2
, save the file and re-open the file - as said: It is just an outline to present the idea
- The Accumulation only works if input cell changes. In other words: Entering the same value does not add the value once more to the Accumulated value (To achieve this: Enter
0
and enter the previous value again). This decision was made to prevent an accumulation of cell A2
on every recalculation of the document, regardless of the cell(s) being changed (reminder: event Content changed triggers macro execution)
Assignment of Macros
Sheet events: Assignment of macros to sheet events can be done through Right click on sheet tab -> Sheet event..
Document events: Assignment of macros to document events can be done through Tools -> Customize -> Tab: Events
Hope that helps.