Hello
If I understand it correctly, you may try something like the following script. It will select column B of last row in used range of table 1. (If table 1 is blank table, it will select B1.)
Regards,
H
_main()
on _main()
tell application "Numbers" -- Numbers v2
tell document 1
set r to choose from list (get sheets's name)
if r = false then error number -128
set r to r's item 1
tell sheet r
my select_sheet(it) -- [1]
tell table 1
set _range to my used_range(it)
if _range is missing value then -- blank table
set selection range to row 1's cell 2
else
set selection range to _range's row -1's cell 2
end if
end tell
end tell
end tell
end tell
(*
[1] this is required to swtich current sheet in Numbers v2
*)
end _main
on select_sheet(_sheet)
(*
reference _sheet : sheet object of Numbers v2
*)
tell application "Numbers"
set _name to _sheet's name
set _doc to (_sheet as record)'s every reference's item 1
end tell
tell application "System Events"
tell process "Numbers"
set frontmost to true
tell (window 1 whose subrole = "AXStandardWindow" and title = _doc's name)
tell splitter group 1
tell splitter group 1
tell scroll area 1
tell outline 1
tell (row 1 whose group 1's static text 1's value = _name)
set selected to true
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end select_sheet
on used_range(_table)
(*
object _table : table object of Numbers v2
return reference : reference to the used range of given table
*)
script o
property strict : true -- true for strict test (with temporary format change) for empty cells, false otherwise
property empty : 0.0 -- value of empty cell (0.0 in Numbers v2)
property xx : {}
property ee : {}
on _undo()
tell application "Numbers" to activate
tell application "System Events"
tell process "Numbers"
keystroke "z" using {command down}
end tell
end tell
end _undo
-- get text value of cells
tell application "Numbers"
tell _table's cell range
if strict then set format to text -- set format to text [1]
set xx to rows's cells's value
if strict then my _undo() -- undo format change
set {ix, jx} to {count rows, count columns}
end tell
end tell
-- get row range i0..i1 and column range j0..j1 of used range
set {i0, i1} to {ix + 1, 0}
set {j0, j1} to {jx + 1, 0}
repeat jx times
set my ee's end to empty
end repeat
repeat with i from 1 to ix
set x to my xx's item i
if x ≠ ee then
if i < i0 then set i0 to i
if i > i1 then set i1 to i
end if
repeat with j from 1 to jx
if (j < j0 or j > j1) and x's item j ≠ empty then
if j < j0 then set j0 to j
if j > j1 then set j1 to j
end if
end repeat
end repeat
-- build object specifier of used range
if i0 * i1 * j0 * j1 = 0 then return missing value
tell application "Numbers"
tell _table
set c0 to row i0's cell j0's name
set c1 to row i1's cell j1's name
return a reference to range (c0 & ":" & c1)
end tell
end tell
(*
[1] An empty cell has value 0.0 even if it is formated as text.
Using this behaviour, empty cell can be distinguished from cell containing empty string ("").
*)
end script
tell o to run
end used_range