=AVERAGE(OFFSET($A$1;first-1;0;last-first;1)) works with any spreadsheet program. In Excel, Gnumeric and LibreOffice Calc you may need to replace semicolons with commas.
The following Basic function is obsolete because it adds a lot of complexity and inefficient Basic code without adding any benefit. Like your VBA and the above formula it takes two integer row numbers and calculates the average between the two given rows in column A. It makes use of the FunctionAccess service of LibreOffice or OpenOffice.
Code: Select all
Function AVG(startRow,rowCount) AS Double
Dim fa, sh, rg
fa = createUnoService("com.sun.star.sheet.FunctionAccess")
sh = ThisComponent.CurrentController.getActiveSheet()
rg = sh.getCellRangeByPosition(0,startRow -1,0,endRow -1)
AVG = fa.callFunction("AVERAGE", Array(rg))
End Function
If I recall correctly...
Code: Select all
rg = ActiveSheet.Range("A1").Offset(startrow -1, 0).Resize(endrow - startrow, 1)
AVG = Application.Average(rg)
would be the corresponding function in VBA. Application.Average calls the built-in Average function.