How to delete certain cells from Numbers?

So I have a large dataset with a lot of "noise" in it. I need to get rid of all these cells that have either "-999" in it or "888".

How can I programmatically do that using the numbers app so I am not doing this all day long?


The following example AppleScript code is one way to achieve what you are asking:

tell application "Numbers"
    tell document 1
        tell sheet 1
            tell table 1
                set the targetCells to a reference to (cells whose value is -999)
                set the value of the targetCells to ""
                set the targetCells to a reference to (cells whose value is 888)
                set the value of the targetCells to ""
            end tell
        end tell
    end tell
end tell

Notes:

The example AppleScript code, was tested in Script Editor under macOS Catalina with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.

  • 1 Assumes necessary and appropriate setting in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.

Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.