You can apply user-defined functions in LibreOffice Calc in the following ways:
You can define your own functions using the Basic-IDE. This method requires a basic knowledge of programming.
You can program functions as add-ins. This method requires an advanced knowledge of programming.
You will now see the Basic IDE.
In the Object Catalog window, double-click on the module where you want to store your macro.
Enter the function code. In this example, we define a VOL(a; b; c) function that calculates the volume of a rectangular solid with side lengths a, b and c:
Function VOL(a, b, c) VOL = a*b*c End Function
Close the Basic-IDE window.
Your function is automatically saved in the selected module and is now available. If you apply the function in a Calc document that is to be used on another computer, you can copy the function to the Calc document as described in the next section.
In stage 2 of "Defining A Function Using LibreOffice Basic", in the \<emph\>Macro\</emph\> dialog you clicked on \<emph\>Edit \</emph\>. As the default, in the \<emph\>Macro from\</emph\> field the \<emph\>My Macros - Standard - Module1\</emph\> module is selected. The \<emph\>Standard\</emph\> library resides locally in your user directory.
If you want to copy the user-defined function to a Calc document:
In the \<emph\>Macro from\</emph\> field select \<emph\>My Macros - Standard - Module1\</emph\> and click \<emph\>Edit\</emph\>.
In the Basic-IDE, select the source of your user-defined function and copy it to the clipboard.
Close the Basic-IDE.
In the \<emph\>Macro from\</emph\> field select \<emph\>(Name of the Calc document) - Standard - Module1\</emph\>. Click \<emph\>Edit\</emph\>.
Paste the clipboard contents in the Basic-IDE of the document.
Once you have defined the function VOL(a; b; c) in the Basic-IDE, you can apply it the same way as the built-in functions of LibreOffice Calc.
Open a Calc document and enter numbers for the function parameters a, b and c in cells A1, B1, and C1.
Set the cursor in another cell and enter the following:
The function is evaluated and you will see the result in the selected cell.