首页 > 解决方案 > 使用 Applescript 从找到的单元格中复制 excel 列

问题描述

我希望能够从找到的单元格中复制一整列。

我已经能够创建一些代码来查找单元格。现在,我需要能够选择找到单元格的整个列,然后将其复制到 AA 列以启动我的宏。

“other_values”列将始终出现在报告中,但很少出现在同一个地方,这对我创建的宏来说是个问题。我想把它放在右边,但总是在同一个位置,以便能够启动我的宏,而无需像我迄今为止所做的那样在数据中间添加列

tell application "Microsoft Excel"

    activate

    set othervalues to "other_values"

    set searchRange to range ("A1:Z1")

    set foundColumn to find searchRange what othervalues with match case

    set rowCount to count of rows

    goto reference foundColumn


end tell

此代码正常工作并选择术语“other_values”,无论它在哪里,知道它始终在文件的第一行。现在它需要选择列并复制它

我意识到我必须完成最困难的部分,但作为 Excel 和 Applescript 的新手,我不知道如何选择整个列

谢谢!

标签: excelapplescript

解决方案


另一种不涉及任何选择的方法:

从使用的范围开始,然后获取“其他值”列。构建 Z 列的范围,然后将“other_values”列复制到那里。

tell application "Microsoft Excel"
    tell worksheet 1 of workbook 1
        
        set cour to columns of used range
        set ic to columns of used range whose value of cell 1 is "other_values" -- gets target column
        
        set fri to first row index of last cell of last item of cour -- gets bottom row number
        set zsa to intersect range1 entire row of range ("A1:A" & fri as text) range2 range ("Z1:Z" & fri as text) -- assembles destination range
        copy range ic destination zsa
    end tell
end tell

推荐阅读