\<bookmark_value\>functions; user-defined\</bookmark_value\>\<bookmark_value\>user-defined functions\</bookmark_value\>\<bookmark_value\>Basic IDE for user-defined functions\</bookmark_value\>\<bookmark_value\>IDE; Basic IDE\</bookmark_value\>\<bookmark_value\>programming;functions\</bookmark_value\>

User-Defined Functions

You can apply user-defined functions in LibreOffice Calc in the following ways:

Defining A Function Using LibreOffice Basic

  1. Choose \<item type=\"menuitem\"\>Tools - Macros - Organize Macros - LibreOffice Basic\</item\>.

  2. Click the \<emph\>Edit\</emph\> button. You will now see the Basic IDE.

  3. Enter the function code. In this example, we define a \<item type=\"literal\"\>VOL(a; b; c)\</item\> function that calculates the volume of a rectangular solid with side lengths \<item type=\"literal\"\>a\</item\>, \<item type=\"literal\"\>b\</item\> and \<item type=\"literal\"\>c\</item\>:

    Function VOL(a, b, c)
    VOL = a*b*c
    End Function

  4. Close the Basic-IDE window.

    Your function is automatically saved in the default 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.

Copying a Function To a Document

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:

  1. Choose \<item type=\"menuitem\"\>Tools - Macros - Organize Macros - LibreOffice Basic\</item\> .

  2. In the \<emph\>Macro from\</emph\> field select \<emph\>My Macros - Standard - Module1\</emph\> and click \<emph\>Edit\</emph\>.

  3. In the Basic-IDE, select the source of your user-defined function and copy it to the clipboard.

  4. Close the Basic-IDE.

  5. Choose \<item type=\"menuitem\"\>Tools - Macros - Organize Macros - LibreOffice Basic\</item\> .

  6. In the \<emph\>Macro from\</emph\> field select \<emph\>(Name of the Calc document) - Standard - Module1\</emph\>. Click \<emph\>Edit\</emph\>.

  7. Paste the clipboard contents in the Basic-IDE of the document.

Applying a User-defined Function in LibreOffice Calc

Once you have defined the function \<item type=\"literal\"\>VOL(a; b; c)\</item\> in the Basic-IDE, you can apply it the same way as the built-in functions of LibreOffice Calc.

  1. Open a Calc document and enter numbers for the function parameters \<item type=\"literal\"\>a\</item\>, \<item type=\"literal\"\>b\</item\>, and \<item type=\"literal\"\>c\</item\> in cells A1, B1, and C1.

  2. Set the cursor in another cell and enter the following:

    =VOL(A1;B1;C1)

  3. The function is evaluated and you will see the result in the selected cell.