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)

Posted on Mar 17, 2013 10:11 AM

Reply
7 replies

Mar 17, 2013 6:58 PM in response to Wayne Contello

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

Mar 17, 2013 8:39 PM in response to 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

Mar 17, 2013 11:26 PM in response to LRK57

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

Mar 17, 2013 11:29 PM in response to LRK57

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 tell


You 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

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.

How can I set a formula in a range of cells using Apple Script?

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