Le 9 févr. 2017 à 22:09, Christopher Stone < email@hidden> a écrit :
Hey Folks,
In Numbers 4.0.5 I figured out how to do a basic lookup and select the found cell.
-------------------------------------------------------------------- # Look Up a Value in a Given Document -------------------------------------------------------------------- tell application "Numbers" tell document "Some Document" tell active sheet tell tables
set theCell to first cell whose formatted value is lookup
if theCell ≠ {missing value} and length of theCell = 1 then set theCell to item 1 of theCell set theRow to theCell's row set selection range to theCell end if
end tell end tell end tell end tell --------------------------------------------------------------------
Is there a more efficient way to do this?
Hello Chris
(1) the instruction set theRow to theCell's row is useless (2) The instruction tell tables lets think that the script search in every table available in the current sheet.It doesn't. If the value exists in table 2 but bot in table 1 it will not be found. So I choose to replace tell tables by tell table 1. Doing that reveals an oddity. length of theCell = 1 is accepted when the script use tell tables, it's not when it use tell table 1. It's due to the fact that the functions count and length aren't completely identical. If I replace length theCell = 1 by (count theCell) = 1 the script works.
So it seems that it would be better to use :
-------------------------------------------------------------------- # Look Up a Value in a Given Document --------------------------------------------------------------------
set lookup to 125
tell application "Numbers" tell document "Some Document" tell active sheet tell table 1
set theCell to first cell whose formatted value is lookup
if theCell ≠ {missing value} and ((count of theCell) = 1) then set theCell to item 1 of theCell set selection range to theCell end if
end tell end tell end tell end tell --------------------------------------------------------------------
Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) vendredi 10 février 2017 12:45:18
|