how to copy multiple sheets in google sheets

Duplicate Multiple Sheets in Google Sheets: A Step-by-Step Guide

By Jessica Moore
AD

Have you ever needed to duplicate multiple sheets in Google Sheets for different purposes, such as maintaining separate records or comparing data? While Google Sheets doesn't have a built-in feature to copy multiple sheets at once, there's a simple workaround using Google Apps Script.

By using a script, you can make this process more efficient, saving you time and reducing the risk of human error. In this guide, we'll walk you through the step-by-step process of copying multiple sheets in Google Sheets.

Understanding Google Apps Script

Before we dive in, let's briefly understand what Google Apps Script is. It's a JavaScript-based scripting language supported by Google. It allows you to automate tasks across multiple Google products and third-party services.

AD
How to add a Calendar into a cell in Google Sheets #googlesheets #tutorial #spreadsheet
How to add a Calendar into a cell in Google Sheets #googlesheets #tutorial #spreadsheet
The Ultimate Google Sheets Keyboard Shortcut Cheat Sheet for Beginners & Pros
The Ultimate Google Sheets Keyboard Shortcut Cheat Sheet for Beginners & Pros
How to Create a Google Dashboard
How to Create a Google Dashboard

For our purpose, we'll use Google Apps Script to create a custom function that will copy multiple sheets in Google Sheets.

Setting Up Google Apps Script

First, you need to open your Google Sheets document, click on "Extensions" in the menu, then "Apps Script." This will open the Google Apps Script editor. Here, you can write, save, and run your scripts.

Basic Formatting in Google Sheets
Basic Formatting in Google Sheets
6 Crazy Google Sheets Formulas You Should Know
6 Crazy Google Sheets Formulas You Should Know
How to find duplicates in Google Sheets
How to find duplicates in Google Sheets

The editor window consists of several panes. You'll primarily work in the "Code.gs" file, which is where you'll write your scripts. On the left sidebar, you'll see your files and their content, and at the bottom, there's a toolbar with useful functions.

Writing the Copy Sheets Script

Now, let's write the script to copy multiple sheets. In the Code.gs file, delete any existing code and replace it with the following:

AD

function copySheets() { var ss = SpreadsheetApp.getActive(); var sheets = ss.getSheets(); for (var i = 0; i < sheets.length; i++) { var newSheet = sheets[i].copyTo(ss); } }

Handy Cheat Sheets – Microsoft Office | CustomGuide
Handy Cheat Sheets – Microsoft Office | CustomGuide
How to Protect Sheets and Ranges in Google Sheets
How to Protect Sheets and Ranges in Google Sheets
How to use Google Sheets: A beginner's guide | Zapier
How to use Google Sheets: A beginner's guide | Zapier
the words sort columns like a pro in google sheets on a green background with an image of
the words sort columns like a pro in google sheets on a green background with an image of
Quick tutorial: How to create dropdowns in Google Sheets (the easy way!)
Quick tutorial: How to create dropdowns in Google Sheets (the easy way!)
Google Sheets Checklists
Google Sheets Checklists

This script does the following:

  1. Gets the active spreadsheet (your Google Sheets document),
  2. Gets all the sheets in the active spreadsheet,
  3. Loops through each sheet,
  4. Creates a copy of the sheet and adds it to the active spreadsheet.

Running the Script

With the script written, it's time to run it. Click the "Save" button in the toolbar, name your project (e.g., "CopySheets"), then click the play icon to run the script.

AD

Running the script will copy all the sheets in your Google Sheets document. Once done, you'll see a confirmation message, and your copied sheets will appear at the end of your sheet list.

the google sheets has hidden gems you're not using on your webpages
the google sheets has hidden gems you're not using on your webpages
How to use VLOOKUP in Google Sheets: A complete guide
How to use VLOOKUP in Google Sheets: A complete guide
The Ultimate Google Sheets Formulas Cheat Sheet
The Ultimate Google Sheets Formulas Cheat Sheet

Modifying the Script for Specific Sheets

If you only want to copy specific sheets, you can modify the script. Replace the script above with the following:

function copySpecificSheets() { var ss = SpreadsheetApp.getActive(); var sheetNames = ["Sheet1", "Sheet2"]; //replace with the names of the sheets you want to copy sheetNames.forEach(sheetName => { var sheet = ss.getSheetByName(sheetName); var newSheet = sheet.copyTo(ss); }); }

AD

Replace "Sheet1" and "Sheet2" with the names of the sheets you want to copy. Running this script will only copy the specified sheets.

Remember, the script's performance depends on the size, complexity, and number of your sheets. Always be careful when running scripts, especially on large or complex documents, to avoid any unintended consequences.

In the world of automation and efficiency, Google Apps Script empowers us to perform tasks in Google Sheets seamlessly. Next time you need to duplicate multiple sheets, knowing this simple trick can save you valuable time and effort.

AD