How can I loop though a column on excel with applescript?

时间:2015-06-25 18:16:15

标签: excel applescript applescript-excel

This is what I have. I just started using applescript so I don't really know the ins and outs. Essentially i want to select the first 50 rows unless there are values of inf in column J. If there are values of inf it should be 50 + that amount.

tell application "Microsoft Excel"
   tell active workbook
       select cell "J1"
       set i to 1
       if value of cell ("J" & i) is equal to "inf" then
           repeat while value of cell ("J" & i) is equal to "inf"
               set i to i + 1
           end repeat
           return i
           set myRows to range "1:50+i"
           select myRows
       else
           set myRows to range "1:50"
           select myRows
       end if
   end tell
end tell

1 个答案:

答案 0 :(得分:0)

try this

tell application "Microsoft Excel"
    tell active sheet
        set i to 0
        if value of range ("J1") = "inf" then
            set i to i + 1
            repeat while value of range ("J" & i) = "inf"
                set i to i + 1
            end repeat
        end if
        set myRows to range ("1:" & 50 + i)
        select myRows
    end tell
end tell