开发者

applescript to compare cell values and then place the value of one cell into another

in a numbers app table i have the following data

   开发者_运维问答A          B                     C                 D
user_id     login                user_id        login
2039        Abbott, Rachael                     Adams, Sue
110         Abbott, Shelby                      Adamson, Wendy
2910        Abraham, Binu                       Anderson, Daryl
121         Adams, Sue
122         Adamson, Anne
126         Adamson, Wendy

i am trying to write an applescript that will...

  1. iterate down logins in column D
  2. to find a matching login in column B
  3. take the value of the user_id in column A at the row where the match was found
  4. and place it into column C in the same row as the entry in column D
set dName to "correlationstudies.numbers"
set sName to "users"
set tName to "Table 1"
set login_row to 2
set login_w_id_row to 2

tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
   repeat
      set login to value of cell login_row of column 4
      if login = "" then exit repeat
      set login_w_id_row to 2

      repeat
         set logincomp to value of cell login_w_id_row of column 2
         if logincomp = login then
            set value of cell login_row of column 3 to value of cell login_w_id_row of column 1
            exit repeat
         end if
         set login_w_id_row to login_w_id_row + 1
      end repeat
      set login_row to login_row + 1
   end repeat
end tell


AppleScript may be superfluous for what you're trying to do. In the numbers documentation, take a look at the VLOOKUP function, which is passed a value to look up, a set of cells to look up in, and the column of the value to return. I got it to work only by swapping the order of the user_id and login columns, but once I put the login in column A and the user_id in column B, setting cell C1=VLOOKUP(D2, A2:B7, 2 ) returned 121 successfully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜