- Code: Select all Expand viewCollapse view
`Function ComputeAverage(firstRow As Long, lastRow As Long) As Double`

Dim i as Long

For i = 2 to 23

firstRow = ActiveSheet.Cells(i,1) + firstRow

Next i

Dim j as Long

For j = 2 to 23

lastRow = ActiveSheet.Cells(j,1) + lastRow

Next j

ComputeAverage = (firstRow+lastRow)/(j-i)

End Function

This code seems as a MS VBA code snippet.

The StarBasic+API functions are not compatibble with the MS VBA.

You must rewrite your MS VBA macrso functions based on the

API functions of the AOO/LO.

And why you used two "For..." cycles to compute the average value of ONE one dimensional cell range?

Why you used constans parameters for the FOR statement, when you need compute a value between two variable row numbers?

Maybe I misunderstood it: you want compute the average of the values in one column between the rows given by the input parameters?

And why you need a macro for computing a simple average value? There is a cell function named AVERAGE() for this task.

- Code: Select all Expand viewCollapse view
`Function ComputeAverage(firstRow As Long, lastRow As Long) As Double`

Dim i as Long

Dim MySum az Double

Dim oDoc as object

Dim oSheet as object

Dim oCell as object

MySum = 0

For i = FirstRow to LastRow

oCell = "put here the API functions to get the actual cell based on the row numbers and the actual sheet, and the actual document..."

MySum = MySum + oCell.Value

Next i

ComputeAverage = MySum/(LastRow-FirstRow)

End Function

You MUST study the API functions for control the documents, rows, cells by your macro code. See the free books: Andrew Pitonyak's books will give you excellent descriptions and examples. And you can find similar examples in this Forum too.

https://forum.openoffice.org/en/forum/v ... f=5&t=7915http://www.pitonyak.org/oo.phphttps://forum.openoffice.org/en/forum/v ... 20&t=88415
Tibor Kovacs, Hungary; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.3 and AOO4.1.3; on Win7x64Prof.

Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.