I’ve been trying to change an Excel macro into a Calc one. The puropse is to count rows of data only when there are certain entries in three different columns. Here’s my original code where WordCol, DirectionCol and NumberCol are integers refering to the numbers of the columns I want to use and Sheet1 = ThisComponent.Sheets(0):
TotalCount = WorksheetFunction.CountIfs(Sheet1.Columns(WordCol.Column), “Yes”, Sheet1.Columns(DirectionCol.Column), “Up”, Sheet1.Columns(NumberCol.Column), 1)
I found this question about using optimalWidth in a macro and can use this code to change the width of the columns (it works as expected for all three columns):
Sheet1.getColumns().getByIndex(WordCol).OptimalWidth = true
Using that style of column selection in my original code still gives an error “BASIC runtime error. Object variable not set.”:
TotalCount = WorksheetFunction.CountIfs(Sheet1.getColumns().getByIndex(WordCol), “Yes”, Sheet1.getColumns().getByIndex(DirectionCol), “Up”, Sheet1.getColumns().getByIndex(NumberCol), 1)
I guess I must be using countifs wrong but couldn’t find any information on how to use it in a macro. So, how do I use countifs in a calc macro?