Automatically Copy Template Monthly in Google Sheets | Bookkeeping Automation
Learn how to automate your bookkeeping in Google Sheets by creating a monthly template that duplicates automatically at the start of each month using Google Apps Script.
you want to create a really simple automation for your bookkeeping this is how to duplicate your monthly template so we're have some expenses and some income and we're putting it all in a sheet every single month here we have January but we're going to turn this into a template let's just duplicate it and call it template and instead of having January and have to copy January to February fill it out then copy February to March fill it out and delete all this stuff we're just going to create a template that's blank everything is structurally going to be the same just it's going to be blank and so this one we're going to copy every single time so we're going to go up to extensions appscript and write a little bit of code follow along step by step as I show you what to do we're going to rename function to duplicate template all one word we're going to try to do is
copy this template Tab and rename it to whichever month it is we're going to do that at the very first of the month every single month two-step process first we need to write our code here and then we need to trigger our code and I'll show you how to set up those triggers it's really really simple once we have this code written so let's write the code we're going to have variable template equals spreadsheet app.get active spreadsheet name and the name is template so what that means is we're getting this spreadsheet app is a built-in function inside of appscript that allows us to access the spreadsheet we're going to access the entire worksheet file and then we're going to get the specific name the specific tab
called template and what are we going to do with that we're going to take template and copy to the spreadsheet app so what we can do is create another variable SS equals spreadsheet app. get active spreadsheet and we're going to just put SS here and SS here now let's run it and see what happens actually we want to set the title set name and here we're going to say new template but we're going to come back and fix this to the month in a second let's just see that it runs so once we save it we're going to click run we may have to authorize the very first time we do this if we go back to our sheet we see that we have a new template we have the entire sheet here this tab is co copied
and named new template so let's delete this and again we want to name it the month maybe we want to also add the year as well so how how do we set that name well we're going to need to get the month and the year so let's get the month this is utilities which is another build-in function that allows us to access something called format date we're going to take today's date literally the DAT today we're going to get the time zone of whatever sheet we're on so we're just going to do session. get script time zone comma and here we create the formatting we're going to do month m m mm that's four M's if we do 2 M's it's going to get us number three M it's going to get us the first three letters of the month and if
we do four M's it's going to get us the entire name of the month we also want to get the year so let's do that utilities. format date new date and this structure is very specific it's NE ew lowercase space capital D date with parentheses again we're going to get the session time zone I'll show you where to set that in a second and we're going to get all four numbers of the year for now and let's set the name as month plus we'll put a hyphen and a space plus here so this will sort of concatenate or create the name of the tab as the full month of the year the full month name
and the year with the hyphen in between so let's hit run while we do that I'm going to go over to project settings on the left here and show you where to set the time zone if the time zone is different than you need to you can set the time zone here this project time zone is different than your sheet time zone you may have to set these separately this is only because we're using this session get script time zone or you can just enter GMT + 1 plus 2 minus one - 6 whatever you want to add let's go back and see we have now January 2025 template created obviously we had January all in caps but this one we have January hyphen 2025 we we can shorten this if we want to just the two numbers of the year and just the first three
letters of the month if we want to use mmm that's three M's and let's even take out the spaces to show you that this is also possible whatever format you want for this name there you go it's a new one called Jan hyphen 25 instead of the very long one maybe you want very short now this will work for every single first of month when you run this on the first of the month now the second part of this video is once we have this template duplicating totally fine we want to run this every single month at the beginning of the month so let's do that over here on the left side triggers click that and come down to the bottom right click add trigger choose which function to run if you have multiple functions you'll have to select it but here we only have one duplicate template
and instead of Select Event Source from spreadsheet we're going to select time driven instead of timer we're going to say month timer and here we get to select the day of the month so we want to run it on the very first day of the month we want to run it as soon as possible maybe or maybe you want to run it closer to maybe when you're going to be available 4 to 5 a.m. beginning of the day let's save this and now this trigger will run between that hour once and then every month afterwards it'll run between that hour now if you get an error it'll show here an error rate and it will show you errors over in executions if you run this multiple times like if I run this right now and I have one already named I might get an
error that says a sheet already exists that's just because I'm running it multiple times with the exact same name you just have to go and delete this and actually it even made a copy already but just didn't name it properly so we can just delete those that might be an error you run into if you try to run this multiple times now it'll work because there doesn't exist a sheet with that name hopefully this is helpful to you setting up your bookkeeping automations every single month saves you a few minutes every month or even every week if you're creating this every week if you're looking to get more out of your spreadsheets than you ever have before consider subscribing here on YouTube to better sheets