Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function ColumnNameToNumber(oSheet As Object, columnName As String) As Integer
- ColumnNameToNumber = oSheet.getCellRangeByName(columnName & 1).getCellAddress().Column
- End Function
- Function CountMoney(oSheet As Object, dateColumn As Integer, moneyColumn As Integer, startDate As Date, endDate As Date) As Double
- Dim oCells As Object : oCells = oSheet.getColumns().getByIndex(dateColumn)
- Dim oNotEmpty As Object : oNotEmpty = oCells.queryContentCells(com.sun.star.sheet.CellFlags.DATETIME)
- Dim nrows As Integer : nrows = oNotEmpty.computeFunction(com.sun.star.sheet.GeneralFunction.COUNT)
- For i = 0 To nrows - 1
- Dim rowDate As Date : rowDate = CDate(oSheet.getCellByPosition(dateColumn, i).Value)
- If startDate <= rowDate And rowDate <= endDate Then
- answer = answer + oSheet.getCellByPosition(moneyColumn, i).Value
- End If
- Next
- CountMoney = answer
- End Function
- Sub Main
- Dim oSheet As Object : oSheet = ThisComponent.Sheets(0)
- Dim inputString As String
- Dim components() As String
- inputString = InputBox("Enter 'dateColumn,moneyColumn,startDate,endDate': dates are in format MM/DD/YYYY, columns are column letters")
- components = Split(inputString, ",")
- Print CountMoney(oSheet, ColumnNameToNumber(oSheet, components(0)), ColumnNameToNumber(oSheet, components(1)), CDate(components(2)), CDate(components(3)))
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement