How to automatically create multiple sheets in Numbers

Hi, I'm looking for a way to automatically create multiple sheets in Numbers.


I need each sheet (tab) to have a different name. For example, a different date for each sheet (tab) such as 1/3/25, 1/17/25, 1/31/25. I have a text list of all the dates that need to be on tabs.


Each sheet needs to have identical tables, too. (Not the same data in every tab's table, just the same structure & formulas.)


Is this possible? Thanks!


Numbers version 14.3 (7042.0.76)


Posted on Dec 20, 2024 11:40 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 24, 2024 6:30 AM

I always advise to avoid having like data in multiple places, such as a similarly structured tables on different sheets. That makes it hard to analyze your data as a whole as it's harder to combine the data in all those tables. Usually it's more efficient to keep your data all together and use filters and formulas or Pivot Tables to pull out subsets and subtotals.


And like Camelot, I also don't like to use GUI scripting unless I have to.


However, if you have a system that is working for you (perhaps you have a monthly financial model in a specific format) and you don't want to change your structure then you can easily automate the "duplication" of a table, using names you have prepared, by using a script like this:


set newSheetNames to {"1/3/25", "1/17/25", "1/31/25"} -- add more as needed within the AppleScript list

tell application "Numbers"
	activate
	tell front document
		set tempSheet to first sheet
		set active sheet to tempSheet
		repeat with aNewSheetName in newSheetNames
			tell application "System Events"
				-- deselect all
				keystroke "a" using {command down, shift down}
				delay 0.1
				-- select all objects (tables, text items, etc.)
				keystroke "a" using {command down}
				delay 0.1
				-- copy the objects
				keystroke "c" using {command down}
			end tell
			delay 0.1
			set newSheet to make new sheet with properties {name:aNewSheetName}
			tell newSheet
				delete every table
				tell application "System Events"
					keystroke "v" using {command down}
				end tell
			end tell
		end repeat
	end tell
end tell


USAGE:


  1. Copy-paste the above script into Script Editor (in Applications/Utilities)
  2. Have your Numbers document open and make the first sheet the way you want it, leaving the formulas you want intact but with the old data cleared out.
  3. Click the triangle 'Run' button in Script Editor.


Your new sheets should appear. (If you have trouble try slightly increasing the delay.)


SG



3 replies
Question marked as Top-ranking reply

Dec 24, 2024 6:30 AM in response to ladysun1969

I always advise to avoid having like data in multiple places, such as a similarly structured tables on different sheets. That makes it hard to analyze your data as a whole as it's harder to combine the data in all those tables. Usually it's more efficient to keep your data all together and use filters and formulas or Pivot Tables to pull out subsets and subtotals.


And like Camelot, I also don't like to use GUI scripting unless I have to.


However, if you have a system that is working for you (perhaps you have a monthly financial model in a specific format) and you don't want to change your structure then you can easily automate the "duplication" of a table, using names you have prepared, by using a script like this:


set newSheetNames to {"1/3/25", "1/17/25", "1/31/25"} -- add more as needed within the AppleScript list

tell application "Numbers"
	activate
	tell front document
		set tempSheet to first sheet
		set active sheet to tempSheet
		repeat with aNewSheetName in newSheetNames
			tell application "System Events"
				-- deselect all
				keystroke "a" using {command down, shift down}
				delay 0.1
				-- select all objects (tables, text items, etc.)
				keystroke "a" using {command down}
				delay 0.1
				-- copy the objects
				keystroke "c" using {command down}
			end tell
			delay 0.1
			set newSheet to make new sheet with properties {name:aNewSheetName}
			tell newSheet
				delete every table
				tell application "System Events"
					keystroke "v" using {command down}
				end tell
			end tell
		end repeat
	end tell
end tell


USAGE:


  1. Copy-paste the above script into Script Editor (in Applications/Utilities)
  2. Have your Numbers document open and make the first sheet the way you want it, leaving the formulas you want intact but with the old data cleared out.
  3. Click the triangle 'Run' button in Script Editor.


Your new sheets should appear. (If you have trouble try slightly increasing the delay.)


SG



Dec 21, 2024 5:01 AM in response to ladysun1969

Numbers has the ability to duplicate a sheet (just check the Inspector -> Sheet when no table is selected)


Unfortunately there's no simple way to automate this (this command is specifically not supported via AppleScript0. It might be viable via UI Scripting, but there are lots of gotchas when dealing with UI scripting.


At a high level, this script (paste it into a new Script Editor document and click Run) will click the Duplicate Sheet button on front window, but it's up to you to make sure the right inspector pane is visible (i.e. no table/cell is selected):


tell application "System Events" to tell process "Numbers"
    click button "Duplicate Sheet"  of window 1
end tell


You could put this in a loop and run it as many times as you like. The script could even read your source file of sheet names and rename the sheets as it goes... it'll just take a little more work

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to automatically create multiple sheets in Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.