In numbers I have columns with data like this:
I want to iterate through cells and for ex. if value of cell in row 6 is not equal to value of. cell in row 5 then add an empty row above the row 6 (below 5)
this is my code but doesn't work:
tell column "A"
set nbr to count rows
set x to 2
repeat with r from x to nbr
set aVal to value of cell r
repeat with s from x + 1 to nbr
set aNVal to value of cell s
if aNVal is not equal to aVal then
add row above s
exit repeat
end if
end repeat
set x to x + 1
end repeat
end tell
In numbers I have columns with data like this:
I want to iterate through cells and for ex. if value of cell in row 6 is not equal to value of. cell in row 5 then add an empty row above the row 6 (below 5)
this is my code but doesn't work:
tell column "A"
set nbr to count rows
set x to 2
repeat with r from x to nbr
set aVal to value of cell r
repeat with s from x + 1 to nbr
set aNVal to value of cell s
if aNVal is not equal to aVal then
add row above s
exit repeat
end if
end repeat
set x to x + 1
end repeat
end tell
Share
Improve this question
edited Feb 11 at 8:23
matt
536k93 gold badges933 silver badges1.2k bronze badges
asked Feb 10 at 17:03
emerogemerog
793 silver badges10 bronze badges
4
|
1 Answer
Reset to default 1You have to flesh things out when you specify stuff, for example: value of cell 1 of row r
.
As suggested by @Willeke, this begins looping at the bottom — otherwise the added row will mess up your repeat loop. It ends at row 3 to keep it from inserting a row above row 2, which otherwise would likely always occur because your header will be different than your data.
You don't actually need the second loop because you are only comparing one row to its predecessor.
tell application "Numbers"
tell column "A" of table 1 of sheet 1 of document 1
set nbr to count rows
set x to 3
repeat with r from nbr to x by -1
if value of cell 1 of row r is not equal to value of cell 1 of row (r - 1) then
add row above row r
end if
end repeat
end tell
end tell
s
but what is that? It is an integer. You need to flesh it out, egrow s
. The reason for the error is that '6
' is not a range. – Mockman Commented Feb 12 at 2:14