AppleScript & Excel:根据另一个单元格的值更改单元格
AppleScript & Excel: change cell based on another cell's value
基本脚本将检查列中的每个单元格,如果该单元格包含特定值,则将其左侧的单元格更改为另一个值。
所以,类似于:
tell application "Microsoft Excel"
set theRange to find column 3
repeat with x from 1 to 50 -- check the first 50 cells of column 3
if theRange x value = "valid" then -- if the cell value/text is "valid"
set currentValue to theRange x -1 value -- get the value of the previous cell in the same row
set the value of theRange x -1 to currentValue & " paid" -- and append the word "paid"
end repeat
end tell
显然,上面的代码是垃圾,但希望你能看到我想要的:
检查第 3 列中的每个单元格(仅使用了 50 行)
如果它有一个给定的值,通过附加一个词
来改变同一行中的前一个单元格
如果您只使用 Excel,我认为这很简单,但我想要一个脚本,我可以 运行 处理多个文件,而无需对每个文件进行硬编码 sheet
此脚本应进行更改。通常建议声明 sheet 和工作簿,以防止脚本 运行 在错误的工作簿或 sheet 上。更改引号之间的值以匹配您的文件,或者如果您不想使用它,请删除对 "of theSheet" 的引用。
tell application "Microsoft Excel"
set theSheet to sheet "sheet name" of workbook "workbook name"
repeat with x from 1 to 50
if value of range ("C" & x) of theSheet = "valid" then
set currentValue to (value of range ("B" & x) of theSheet as string) & " paid"
set the value of range ("B" & x) of theSheet to currentValue
end if
end repeat
end tell
基本脚本将检查列中的每个单元格,如果该单元格包含特定值,则将其左侧的单元格更改为另一个值。
所以,类似于:
tell application "Microsoft Excel"
set theRange to find column 3
repeat with x from 1 to 50 -- check the first 50 cells of column 3
if theRange x value = "valid" then -- if the cell value/text is "valid"
set currentValue to theRange x -1 value -- get the value of the previous cell in the same row
set the value of theRange x -1 to currentValue & " paid" -- and append the word "paid"
end repeat
end tell
显然,上面的代码是垃圾,但希望你能看到我想要的:
检查第 3 列中的每个单元格(仅使用了 50 行) 如果它有一个给定的值,通过附加一个词
来改变同一行中的前一个单元格如果您只使用 Excel,我认为这很简单,但我想要一个脚本,我可以 运行 处理多个文件,而无需对每个文件进行硬编码 sheet
此脚本应进行更改。通常建议声明 sheet 和工作簿,以防止脚本 运行 在错误的工作簿或 sheet 上。更改引号之间的值以匹配您的文件,或者如果您不想使用它,请删除对 "of theSheet" 的引用。
tell application "Microsoft Excel"
set theSheet to sheet "sheet name" of workbook "workbook name"
repeat with x from 1 to 50
if value of range ("C" & x) of theSheet = "valid" then
set currentValue to (value of range ("B" & x) of theSheet as string) & " paid"
set the value of range ("B" & x) of theSheet to currentValue
end if
end repeat
end tell