Ask Your Question

How to create a user defined function

asked 2018-06-22 18:55:35 +0100

Calcasieu gravatar image

How do I get a function that says if B2 or C2 is empty the result is empty, but otherwise C2 is divided by B2

edit retag flag offensive close merge delete



The term "user defined function" for Calc is commonly supposed to mean a function added - based on user code, that's by programming - to the standard functions of Calc. What you got suggested by @hjek and accepted as a correct answer is not something of that kind. In commonly used terms it is a formula (aka spreadsheet-formula"). Given the literal subject the other answer was correct though probably not very helpful to you. No reason, however, to downvote it. Serious attempt to help!

Lupp gravatar imageLupp ( 2018-06-23 01:01:55 +0100 )edit

2 Answers

Sort by » oldest newest most voted

answered 2018-06-22 20:22:45 +0100

hjek gravatar image

updated 2018-06-22 20:24:23 +0100

It's fairly simple to literally translate your requirements

if B2 or C2 is empty the result is empty, but otherwise C2 is divided by B2

to a formula

=IF(OR(ISBLANK(B2), ISBLANK(C2)), "", C2/B2)

I think your question is good and precise, but the headline is misleading, because User-Defined Functions has to do with using macros to defined named functions, whereas your problem can be solved just fine with a simple formula.

(If this works for you, please click on the ✓ to accept the answer.)

edit flag offensive delete link more


Works perfect. Many thanks.

Calcasieu gravatar imageCalcasieu ( 2018-06-22 21:52:51 +0100 )edit

answered 2018-06-22 19:27:42 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Every macro written in LO BASIC as FUNCTION can be used as function in Calc. LO BASIC Functions, when used as Calc functions, get the current cell as parameter and return a value to the cell.

Edited by @Lupp:
More precise: The parameters passed to the function are described by the parameter list appended (enclosed in parentheses) to the function's name. Each parameter may be a constant or a reference or a formula again. When called from a cell's formula the function gets passed parameters always as if specified 'ByVal' in Calc. (Excel may do it otherwise.)

edit flag offensive delete link more



Thanks for your answer. I am not proficient in Libre and am not familiar with the terms LO BASIC. Can you refer me to a source that explains this in more basic terms?

Calcasieu gravatar imageCalcasieu ( 2018-06-22 20:01:04 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-22 18:55:35 +0100

Seen: 1,170 times

Last updated: Jun 23 '18