使用 Applescript 从找到的单元格中复制 excel 列

Duplicating an excel column from a found cell with Applescript

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

我已经能够创建一些代码来查找单元格。现在,我需要能够 select 找到单元格的整个列,然后将其复制到 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

此代码可以正常工作,并且 select 术语 "other_values" 无论它在哪里,知道它总是在文件的第一行。现在它需要 select 列并复制它

我意识到我一定已经完成了最困难的部分,但作为 Excel 和 Applescript 的新手,我不知道如何 select 整个专栏

谢谢!

如果有人遇到同样的问题,这里是答案:

##Find Other Values Column

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
    goto reference foundColumn

    ##Duplicate Column##

    set addr to get address (column 1 of selection)
    set addr to text 2 thru 2 of addr
    ## e.g range $H:$H"
    set myWantedRange to "$" & addr & ":$" & addr
    set src to range myWantedRange of sheet 1 of workbook "Workbook1"
    set dst to range "$Z:$Z" of sheet 1 of workbook "Workbook1"

    copy range src destination dst
end tell

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

从使用的范围开始,然后获取 'other_values' 列。为 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