Adding column to multiple identically formatted tables in Numbers

applescriptautomationautomatorms officenumbers

I have a document in Number that contains many tables with the same format/columns but different content. I'd like to modify the format for all, adding a new, empty column in the same place with the same title, without having to edit each individual table.

An example: I'm tracking reading progress in multiple different books and would like to add a new field to track some additional data.

Is this feasible in Numbers, maybe with some AppleScript, or am I better off trying Excel with VBA?

I'd also be willing to try reorganizing my data in such a way that I don't need to do this, e.g., concatenating the tables vertically would probably work; I'd just like to know if there's a cleaner alternative as the separation into tables has made it simpler to organize the tables themselves.

Best Answer

I'm not sure I understand your question exactly. But, if all of the tables are on one sheet, and all of the tables need to get the same new column and the same column title, this will work.

Screenshot of Numbers document with three tables on the sheetScreenshot of Numbers document with three tables on the sheet, before running the script.

Screenshot of Numbers document with three tables on the sheet, column added and titledScreenshot of Numbers document with three tables on the sheet, with column added and titled

Here is the AppleScript that adds the column and names it.

tell application "Numbers"
    set theTables to every table of active sheet of document 1
    repeat with aTable in theTables
        set myColumn to add column before column "B" of aTable
        set value of first cell of myColumn to "Birthplace"
    end repeat
end tell

A few notes-- you can add a column "before" or "after." Also, you can refer to a column by the letter atop the column, as I did here, but you can also refer to a column by the label in the Header row. In this case, that would be Column "Month".