• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Numbers – Look-Up a Value in a Worksheet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Numbers – Look-Up a Value in a Worksheet


  • Subject: Re: Numbers – Look-Up a Value in a Worksheet
  • From: Yvan KOENIG <email@hidden>
  • Date: Fri, 10 Feb 2017 12:45:39 +0100


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



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Numbers – Look-Up a Value in a Worksheet
      • From: Christopher Stone <email@hidden>
References: 
 >Numbers – Look-Up a Value in a Worksheet (From: Christopher Stone <email@hidden>)

  • Prev by Date: Numbers – Look-Up a Value in a Worksheet
  • Next by Date: Displaying Applescripts scroll in the menu bar
  • Previous by thread: Numbers – Look-Up a Value in a Worksheet
  • Next by thread: Re: Numbers – Look-Up a Value in a Worksheet
  • Index(es):
    • Date
    • Thread