set lookup to "125"tell application "Numbers"
tell document 1 --"Some Document"
tell active sheet
tell tables
# On a sheet with two tables
set theCells to cells whose formatted value is lookup # returns a list of lists of cells
# If there is matches in both tables
--> {{cell "C10" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6", cell "D12" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6", cell "E14" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"}, {cell "B3" of table 2 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"}}
# if there is a match only in table 2
--> {{}, {cell "B4" of table 2 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"}}
# If there is no match
--> {{}, {}}
set theCell to first cell whose formatted value is lookup # returns a list of cells
# If there is matches in both tables
--> {cell "C10" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6", cell "B3" of table 2 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"}
# if there is a match only in table 2
--> {missing value, cell "B4" of table 2 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"}
# If there is no match
--> {missing value, missing value}
(*
if theCell ≠ {} then
set theCell to last item of theCell
try
row of theCell as text
on error errMsg number errNbr
set theTable to item 1 of my decoupe(item 2 of my decoupe(errMsg, "«class NmTb» "), space)
end try
set theRow to theCell's row's address
set selection range to theCell
end if
*)
end tell
tell table 1
set theCells to cells whose formatted value is lookup # returns a list of lists of cells
# If there is matches in table 1
--> {cell "C10" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6", cell "D12" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6", cell "E14" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"}
# If there is no match in table 1
--> {}
set theCell to first cell whose formatted value is lookup # returns a list of cells
# If there is matches in table 1
--> cell "C10" of table 1 of sheet 1 of document id "85BABE62-4FFD-439C-B60E-D6565F9C9EB6"
# If there is no match in table 1
--> error number -1719 from cell 1 of table 1 of active sheet of document 1 whose formatted value = "127"
(*
if theCell ≠ {} then
set theCell to last item of theCell
try
row of theCell as text
on error errMsg number errNbr
set theTable to item 1 of my decoupe(item 2 of my decoupe(errMsg, "«class NmTb» "), space)
end try
set theRow to theCell's row's address
set selection range to theCell
end if
*)
end tell
end tell
end tell
end tell
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) samedi 11 février 2017 11:51:07