繁体   English   中英

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,我认为这很简单,但我想要一个脚本,我可以运行多个文件而无需对每个工作表进行硬编码

此脚本应该进行更改。 通常建议声明工作表和工作簿,以防止脚本在错误的工作簿或工作表上运行。 更改引号之间的值以匹配您的文件,或者如果您不想使用它,则删除对“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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM