# Make a macro update its result automatically. [closed]

I just finished coding my first macro and I followed the necessary steps so that it can be called as a regular function in Calc.

The problem is, once I have written my custom function in a cell ( =MyFunction() ), the result gets calculated and the cell that stores the result gets updated with the correct value. However that cell doesnt show the function name like a built-in function would, it just has the result there as if I had written it myself manually. Another problem that arises is that after more data is introduced in the sheet, I need to rerun the function every time, instead of it updating automatically.

So my question is, is there anything that needs to be configured in the macro code or anywhere so that the cell that gets written by the macro gets updated automatically like it would with a build-in function?

Sory if this is a duplicate, I tried looking this up but coulnd't find anything regarding it.

Edit 1 : I do manually return the result of the macro onto a specific cell, in this case AF3

Dim AFX As Object
AFX = ThisComponent.Sheets(0).getCellRangeByName("AF3")
AFX.Value = Value


Value has been calculated properly before

Edit 2 : Okay I just figured out the problem and solution, the quote from Mike

"(are you setting content of some cells directly from your function?)"

and from Lupp

"Did you assign the result to the name of the function as required?"

Made me realise the code above is the problem, so I looked into the docs further in and saw this which went past me last time I was checking these docs: https://documentation.libreoffice.org... (End of Page 9)

I didnt realize you could assing a value to the Function Name, which results in exactly what I wanted. Basically just changed the code above for this:

Function_Name_Implementation = Value


And it works like a charm, thanks.

edit retag reopen merge delete