count cells in a range in macro [closed]
I have a cellrange and I'm trying to get the number of cells populated in that range.
oCellRange = rr_sheet.getCellRangeByName("a63:b68")
I tried count=oCellRange.computeFunction(com.sun.star.sheet.GeneralFunction.COUNT), but that gives the total number of rows in the range, I just want the ones that have data.
I tried the above call with COUNTA, but that complained and said it was not found. I could write a little function that loops through the DataArray, but I was trying to avoid that.
May be cellsCount = oCellRange.getRows().getCount() * oCellRange.getColumns().getCount() Why not?
the getCount() does the same thing, it counts all of the rows in the range, not just the ones that are occupied.
Oh, excuse me! I did not notice the word "populated"! :-( Difficult to publish the code in the comments, I'll publish it in a reply
no worries. Yea, I ended up writing a little function to return the count of populated cells. Thanks, mine looks very similar to yours.