Skip to content

Instantly share code, notes, and snippets.

@plytro
Created February 22, 2012 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plytro/1881471 to your computer and use it in GitHub Desktop.
Save plytro/1881471 to your computer and use it in GitHub Desktop.
smith running total
REM ***** BASIC *****
Option Explicit
Sub calcSeries
Dim oSheet As Object
Dim iCell as Object, oCell As Object
Dim dataStartColumn as Integer, rowOffset as Integer
Dim inputColumn as Integer, inputRow as Integer
Dim outputColumn as Integer, outputRow as Integer
Dim nextValue as Integer
nextValue = 0
Dim total as Integer
total = 0
dataStartColumn = 1 'column b
inputRow = 8 'row 9
rowOffset = 8
outputColumn = 26 'column AA
outputRow = 0 'row 1
oSheet = ThisComponent.getCurrentController().ActiveSheet
Dim continueFlag as Boolean, innerContinueFlag as Boolean
continueFlag = true
do while continueFlag
inputColumn = dataStartColumn
innerContinueFlag = true
do while innerContinueFlag
iCell = oSheet.getCellByposition(inputColumn, inputRow) 'B9
if inputColumn = dataStartColumn AND icell.getType() = com.sun.star.table.CellContentType.EMPTY then
continueFlag = false
exit do
end if
if iCell.getType() = com.sun.star.table.CellContentType.VALUE then
nextValue = iCell.getValue()
total = total + nextValue
oCell = oSheet.getCellByposition(outputColumn, outputRow)
outputColumn = outputColumn + 1
oCell.setValue(total)
else
exit do
end if
inputColumn = inputColumn + 1
loop
inputRow = inputRow + rowOffset
loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment