Use a spreadsheet calculation as a formula elsewhere?

Hi,


I need to create custom functions that are computed in a spreadsheet. Then, in another spreadsheet, I want to use that custom function as a formula.


As a simple example, I want to create a custom function that adds 2 to its input. I'd create a small spreadsheet, Table 1, that has an "input" cell (the input to the function), and an "output" cell (the result of the function). The input cell is A1, and the output cell is B1 and has the formula "=A1+2".


Then, in another spreadsheet, Table 2, I'd somehow (and this is what I don't know) say that I want to pass a value into the input cell and read the value of the output cell. So if Table 2 has A1 equal to 5, and I put into B1 the function SPREADSHEETFUNC( "Table 1", "A1", "B1"). This imaginary function takes as arguments the table name which computes the function (Table 1), the input cell (A1), and the output cell (B1).


So, if Table 2::A1 is 5, the Table 2::B1 would be 7.


If I change Table 2::A1 to -2, Table 2::B1 changes to 0.


I know there's no SPREADSHEETFUNC() function, but is there anyway I can accomplish this?


The motivation is that I want to define a custom function once and then use it in several different tables on my sheet.


Thanks, Eric

MacBook Pro 16″, macOS 10.15

Posted on Aug 15, 2022 5:37 PM

Reply
5 replies

Aug 15, 2022 9:01 PM in response to Eric Goodill1

In Excel you can create custom functions using Visual Basic Editor then use them in your spreadsheet just like the built-in functions. Numbers does not have this ability. That's kind of what you are asking for.


https://support.microsoft.com/en-us/office/create-custom-functions-in-excel-2f06c10b-3622-40d6-a1b2-b6748ae8231f


In Numbers I cannot think of a way to change f(x) in one place and have it apply to all the other places that use the same f(x). But if you use a column to calculate f(x), all you would need to do is change the top cell then copy/paste to all the others in the column.

Aug 15, 2022 6:33 PM in response to Wayne Contello

Thanks for your answer. I've used AppleScript before, but I always struggle with the syntax even though I'm a professional programmer. I may look into that if I have to.


What I'm trying to do is visualize how various root-finding algorithms work (e.g., secant method, Newton's method, bisection method, etc.). I want to have a spreadsheet (table "f(x)") which computes the function whose roots I want to find. I want to graph the function, so I need a table of (x, f(x)) values for the graph as a visual aid (table "Plot"). In a third table (table "Algorithm"), I want to compute one iteration of the root-finding algorithm per row. Each iteration usually involves two computations of f(x) since I need to find the slope of the line connecting points (x1, f(x1)) and (x2, f(x2)). Each row of table "Algorithm" has updated x1 and x2 values. So I'm evaluating f(x) maybe 100 times total among the tables, and I want to change my definition of f(x) in just one place and have the all the cells in each table reflect the new f(x). As a proof of concept, I've hardcoded f(x) into tables "Plot" and "Algorithm", and it's working fine, but now I want to start playing with different definitions of f(x). I hope that makes sense.


-Eric

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Use a spreadsheet calculation as a formula elsewhere?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.