How can I set a formula in a range of cells using Apple Script?
Hi,
I want to set a formula in a range of cells which is referring to other cells in a table? How can one do this in Numbers using Apple Script?
LRK57
iMac, Mac OS X (10.7.5)
Hi,
I want to set a formula in a range of cells which is referring to other cells in a table? How can one do this in Numbers using Apple Script?
LRK57
iMac, Mac OS X (10.7.5)
LRK,
can you provide any context for this question? Sometime context helps one focus on a solution.
Wayne
Hi Wayne,
Thank you for your response.
Say I want to set the formula "=H1+I1" in cell "A1" and extend the same to the range "A1:G15".
In Excel I know how to do it using Apple Script:
Tell application "Microsoft Excel"
activate
set myRange to range "A1:G15" of sheet "Sheet1" of active workbook
set formula of myRange to "=H1+I1"
end tell
But in Numbers it doesn't work. It does not understand the word formula. If one writes the same for Numbers, the word Formula is apparently identified as a variable.
Hope this helps you to find an answer.
LRK
Here is how to place a formula in A1 of table 1 of sheet 1:
tell application "Numbers"
tell front document
tell table 1 of sheet 1
set value of cell 1 of row 1 to "=D1+E1"
end tell
end tell
end tell
What Wayne says.
The context might help understand why you think it is necessary, or would be advantageous to use a script for this.
Regards,
Barry
Hi Barry,
I make repeated scientific calculations based on formulas (or equations) put into thousands of cells which make use of some other data put into cells in worksheets of the same workbook. In Excel I use to inset the equation into a range of cells so that those cells derive data from the relevant range of cells as dictated by the equation. It is therfore advantages to use a script for this.
Regards!
LRK
I see by the time stamps I had opened the initial message and reply prior to your second message and Wayne's reply, and not checked back for an update before reading and responding.
For a small range, such as you've described, the 'manual' process would seem as efficient as setting up a script (leavng out the consideration of having to repeat the process a large number of times).
Enter the formula in A1. Copy the cell.
Shift click on G15 to select the whole range.
Paste.
Those steps might also be translatable to a script or an Automator action.
If you are using the same formula in a number of cases, and know the maximum number of rows an columns that will be occupied by the data in each case, you might be able to set up a template with the formula(s) built in to one or more summary tables, referencing a data table into which you enter or import the data.
Alternates to consider, if scripting does not fill the bill. Post a new question if you want to pursue either of these.
Regards,
Barry
Hello
You may try something like this.
tell application "Numbers"
tell document 1
tell sheet 1
tell table 1
set range "A1:A15"'s cell's value to "=H1+I1"
end tell
end tell
end tell
end tellYou can set all values in a range to the same value in this way. But unlike Excel you cannot set values in a range to a list of values in Numbers, in which case you have to iterate through the cells in range one by one.
Regards,
H
How can I set a formula in a range of cells using Apple Script?