CellRange as parameter in user defined function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Rainer
Posts: 5
Joined: Wed Apr 09, 2008 10:00 am

CellRange as parameter in user defined function

Post by Rainer »

Hi,

I'm a beginner in writing user-defined functions with startbasic and my problem is to give a cell range to my function and use it there. Maybe somebody can give me an short example.

I want to check that the range has a width of only one column and get the value of the cell in the range with have the same row as the cursor is positioned. This value should be divided through the minimum value of the range and the result should the filled in the cell where the cursor is positioned.

Thanks for help
Rainer
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: CellRange as parameter in user defined function

Post by Villeroy »

X1 =$A1/MIN($A$1:$A$65536) [the first A1 with relative row reference]
You may want to read the tutorial on relative/absolute addressing in this forum's tutorials.
Last edited by Villeroy on Wed Apr 09, 2008 1:38 pm, edited 1 time in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Rainer
Posts: 5
Joined: Wed Apr 09, 2008 10:00 am

Re: CellRange as parameter in user defined function

Post by Rainer »

Thank you for your answer Villeroy, but you don't hit my problem.

I want to give a cell-range into a user-defined function and calculate the minimum of the cell-range there.
I also need information about the cell the cursor is in. (at least row and column)

Help needed anymore
Rainer
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: CellRange as parameter in user defined function

Post by Villeroy »

As a matter of fact, any userdefined function --be it written as Basic macro or c++ add-in-- gets values. The application never passes range objects.
So your function would be called with references anyway:
X1 =MYFUNCTION($A1;$A$1:$A$65536)

This is how all spreadsheets use to work and I always recommend to use it just like that. Avoid all macros and userdefined functions in particular. For better performance, readability, ease of debugging, portability and compatibility.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Rainer
Posts: 5
Joined: Wed Apr 09, 2008 10:00 am

Re: CellRange as parameter in user defined function

Post by Rainer »

Hi,

I solved my problem. It was as Villeroy stated that no ranges are passed to functions. But They are passed as array and via LBound and UBound the number of cells in the array can be determined.

Thanks
Rainer
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: CellRange as parameter in user defined function

Post by Villeroy »

Rainer wrote:Hi,

I solved my problem. It was as Villeroy stated that no ranges are passed to functions. But They are passed as array and via LBound and UBound the number of cells in the array can be determined.

Thanks
Rainer
Yes, but there is no concept of "this cell", "this sheet", "this row", "this anything",...
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply