I am new to Apple Script. I have a script for Numbers which I used to automate the creation of a list. In Numbers, I input 4 numbers into the spreadsheet, those numbers undergo a series of tests against a set of rules and eventually Pass/Fail. Apple Script sequentially inputs the 4 numbers, then looks at whether the numbers Passed. If they did so, then the numbers are put into the list. If not, Apple Script moves on to inputing the next set of 4 numbers, etc.
I need to increase the row number of the cell references by 1, whenever a new set of 4 numbers pass the test (i.e. “cn3” ≠ 0), so that eventually I will have a list of all the sets of 4 numbers which passed (268 rows). I did this in Numbers by doing this:
if the value of cell "cn3"≠0 then
set x to x+1
set cellnumberA to “cj” & x
set the value of cell (cellnumberA) to the value of cell “an3”
When I exported the Numbers file to Excel and changed the Apple Script to “Microsoft Excel”, it mostly works in Excel. It’s going through the tests and inputing the next set of 4 numbers. But it’s not making a list of the passing numbers. I’m guessing there’s something wrong with how I’m making the new cell references for Excel.
I want to run this in Excel - partly because I heard Excel was faster and it currently takes almost 13 minutes to generate the list in Numbers. But mostly because I want to teach the special set of rules and I figure Excel is more universal than Numbers.
Please note, I’ve already bumped up the cell numbers to “xx3” (and changed the application to “Microsoft Excel”) because Excel seems to have an extra row at the top (so AN2 is now AN3, for example). The value of cell “AN3” fills appropriately with the new values. What’s not filling is “cell (cellnumberA)” (and cellnumberB, etc.), which start out blank and are supposed to fill in whenever the new 4 numbers PASS. I know from experience that the correct answer is 268 rows total, but it’s meant to be open ended.
I’ll look at the full code momentarily but if the sole issue is the cell reference, then your fourth line (from the initial post) needs to be amended to something like this:
set the value of cell cellnumberA to get value of cell "an3"
ie preface with get
The get here will force the acquisition of the value.
You can remove the parentheses around ‘cellnumberA’.
Thanks for posting the code. Ideally, it should be posted as text, as indicated below, using three backticks in the line above and below the code, like this below. It makes it easier to read and to copy/paste.
```
tell application “Numbers”
tell the first table of the active sheet of document 1
set x to “2”
set cellA to “1”
[… rest of code]
```
Thank you! That did the trick - it’s now running in Excel.
And thank you for the tip on how to get the copy/paste to read correctly.
tell application "Microsoft Excel"
set x to "3"
set cellA to "1"
set cellB to "1"
repeat with L from cellA to 16
set the value of cell "an3" to L
repeat with k from cellB to 16
set the value of cell "ao3" to k
if the value of cell "cj3" ≠ 0 and the value of cell "ck3" ≠ 0 then
repeat with j from cellA to 16
set the value of cell "ap3" to j
repeat with i from cellA to 16
set the value of cell "aq3" to i
if the value of cell "cn3" ≠ 0 then
set x to x + 1
set cellnumberA to ("cj" & x) as text
set cellnumberB to ("ck" & x) as text
set cellnumberC to ("cl" & x) as text
set cellnumberD to ("cm" & x) as text
set the value of cell cellnumberA to get value of cell "an3"
set the value of cell cellnumberB to get value of cell "ao3"
set the value of cell cellnumberC to get value of cell "ap3"
set the value of cell cellnumberD to get value of cell "aq3"
end if
end repeat
end repeat
end if
set cellB to cellA + 1
end repeat
set cellA to cellA + 1
end repeat
end tell