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...
- iterate down logins in column D
- to find a matching login in column B
- take the value of the user_id in column A at the row where the match was found
- 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.