_Ad239

Q: Use Applescript to Filter Column A in Numbers

Hi there,

 

Using Applescript and Numbers, I want to filter column A by three values, then copy the result to a new sheet.

 

The document I'm working on contains thousands of lines and Numbers handles this a lot faster than Excel on my mac, so if possible, I'd like to find a solution that works in Numbers.

 

I guess the filter part would look something like this? (although obviously, this isn't working)

 

 

tell application "Numbers"

    tell document 1's sheet 1's table 1

        tell column 1

            string = "Adam, Jane, David"

                        set filtered to true

        end tell

    end tell

end tell

Posted on Oct 17, 2016 4:13 AM

Close

Q: Use Applescript to Filter Column A in Numbers

  • All replies
  • Helpful answers

  • by SGIII,

    SGIII SGIII Oct 18, 2016 12:31 PM in response to _Ad239
    Level 6 (10,796 points)
    Mac OS X
    Oct 18, 2016 12:31 PM in response to _Ad239

    You of course don't need a script to do this.  You can instead use the Sort & Filter panel at the right to filter on your values (or filter using the dropdown list next to the column later). Then select the filtered cells in the column, command-c to copy, click once in a destination cell, and command-v to paste.

     

    If you need a script you can try something like this.  Click once somewhere in the column you want to filter and run. The script places the filtered results on the clipboard so you single single-click a cell wherever you want the results, and command-v to paste.

     

    SG

     

     

    set filterValues to {"Adam", "Jane", "David"}

     

    tell application "Numbers"

      tell front document's active sheet

      tell (first table whose selection range's class is range)

      set c to selection range's first cell's column

      set vv to c's cells's value whose value is not missing value

      end tell

      end tell

    end tell

     

    set pasteStr to ""

    repeat with v in vv

      tell v to if it is in filterValues then set pasteStr to pasteStr & v & return

    end repeat

     

    set the clipboard to pasteStr

     

    return pasteStr -- optional; to see results in Script Editor 'Result' pane