Sort a range of rows in Numbers

Hello

The Applescript dictionary of Numbers state :

sort‚v : Sort the rows of the table.
sort table
by column : The column to sort by.
[direction ascending/descending]
[in rows range] : Limit the sort to the specified rows.

Alas, I made a lot of attempts but I never found the correct syntax required to define the range of rows.

Is somebody able to give the correct syntax to apply the sort to the range row 2 to row 6 ?


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
sort by column 1 direction ascending -- in rows 2 thru 6
end tell

Thanks in advance.

Yvan KOENIG (VALLAURIS, France) vendredi 22 octobre 2010 19:24:19

Hi, Yvan.

The syntax appears to be the very unattractive:


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
	sort by column 1 direction ascending in rows range "A2:A6" -- or any range involving these rows.
end tell

I personally prefer to extract the data, sort it with one of my own AppleScript sorts, and paste it back in using GUI Scripting. It’s quite a bit of code and presents its own problems with maintaining the cell formats in some situations, but it’s a far more flexible arrangement.

Thanks Nigel

Here is a version which use a calculated range :


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
	sort by column 1 direction ascending in rows range (name of cell 2 of column 1 & ":" & name of cell 8 of column 1)
end tell

Yvan KOENIG (VALLAURIS, France) samedi 23 octobre 2010 12:54:55