---
title: How to Copy a Row to another Sheet with Google Apps Script » saperis
description: Learn how you can copy a row, or multitple rows, from one sheet to another in a Google Sheets document by using Google Apps Script!
image: https://www.saperis.io/hubfs/Imported_Blog_Media/how-to-copy-a-row-to-another-sheet-with-google-apps-script.png
---

[![logo saperis 0.5x-2](https://www.saperis.io/hubfs/logo%20saperis%200.5x-2.png)](https://www.saperis.io)

- [PRODUCTS](https://www.saperis.io/products)
- [ABOUT US](https://www.saperis.io/about)
- [BLOG](https://www.saperis.io/blog)

Google Workspace Tutorials

# How to Copy a Row to another Sheet with Google Apps Script

Learn how you can copy a row, or multitple rows, from one sheet to another in a Google Sheets document by using Google Apps Script!

[Admin](https://www.saperis.io/blog/author/admin)

 Nov 26, 2020

---

# How to Copy a Row to another Sheet with Google Apps Script

- [Chanel Greco](https://saperis.io/author/chanelgreco/)
- [November 26, 2020](https://saperis.io/2020/11/26/)
- 2:01 pm

You want to copy a row, or multiple rows, from one sheet to another in Google Sheets using Google Apps Script?

In that case you can follow along in this Apps Script tutorial! We’ll learn how to copy rows by using either the setValues or copyTo method.

If you’re anything like me, you might enjoy watching the [video](https://youtu.be/xmtwWKYLJHs) of this tutorial. 

 

## Create a Google Sheet document

The first step is to create a Google Sheet document with a source sheet and a target sheet. In this tutorial our source sheet is named “Source” and our target “Target”. Then head over to the Script Editor to start coding.

If you’ve never written a line of Google Apps Script before or you just want to refresh your knowledge then check out [this blog post](https://saperis.io/google-apps-script-tutorial-for-beginners-automate-formatting/).

![Copy a Row with Google Apps Script](https://www.saperis.io/hs-fs/hubfs/Imported_Blog_Media/copy-row-google-apps-script.png?width=541&height=318&name=copy-row-google-apps-script.png)

*After creating your document open the Script editor*

## Copy Row with Google Apps Script by Using the setValues Method

We start off by getting the active spread sheet and then getting the source sheet by name.

Then we’ll use the *getDataRange* and *getValues* methods to get the data from our source sheet.

Next we want to find out how many rows and columns we have in our source sheet. This information is needed for defining the range we want to write our data into on the target sheet.

Then it’s time to get our target sheet by name as well as the range to copy our data to.

The last line of code is the actual copying of our data to our target(range).

```
function copyRowsWithSetValues() {
  let spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  let sourceSheet = spreadSheet.getSheetByName('Source');
  
  let sourceRange = sourceSheet.getDataRange();
  let sourceValues = sourceRange.getValues();
  
  let rowCount = sourceValues.length;
  let columnCount = sourceValues[0].length;
  
  let targetSheet = spreadSheet.getSheetByName('Target');
  let targetRange = targetSheet.getRange(1, 1, rowCount, columnCount);
  
  targetRange.setValues(sourceValues);
} 
```

## Copy Row with Google Apps Script by Using the copyTo Method

Also with this way of copying rows to another sheet we start off with getting our spread sheet and the source sheet.

Once we’ve got that information we get the data range on our source sheet. We **do not** have to get the values as we had to do in the previous example.

Instead, we directly get our target sheet and copy the source range to that sheet.

```
function copyRowsWithCopyTo() {
  let spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  let sourceSheet = spreadSheet.getSheetByName('Source');
  
  let sourceRange = sourceSheet.getDataRange();
  
  let targetSheet = spreadSheet.getSheetByName('Target');
  
  sourceRange.copyTo(targetSheet.getRange(1, 1));
} 
```

 

 

 

## setValues vs. copyTo

The obvious question at this point is: Should you use *setValues* or rather *copyTo* to copy rows from one sheet to another with Google Apps Script?

The short answer is: It depends. Here my suggestions on when to use which method.

You’re copying data from one sheet to another and both sheets are in the same document? Then I would use the *copyTo* method.

You’re copying data from one sheet to another sheet which is located in a different document? Then you have to use *setValues* as *copyTo* only works within the same document.

And also note that in order to use the *setValues* method you have to pass in a two-dimensional array. If you’re using the *copyTo* method, on the other hand, you need a data range.

 

[Google Workspace Tutorials](https://www.saperis.io/blog/tag/google-workspace-tutorials) [Google Apps Script](https://www.saperis.io/blog/tag/google-apps-script)

## Similar posts

<https://www.saperis.io/blog/google-apps-script-tutorial-for-beginners-automate-formatting>

Google Workspace Tutorials

### [Google Apps Script Tutorial for Beginners](https://www.saperis.io/blog/google-apps-script-tutorial-for-beginners-automate-formatting)

In this Google Apps Script tutorial for beginners you'll learn how to automate the formatting of a Google Sheets document.

 Admin  Jan 5, 2021

<https://www.saperis.io/blog/google-sheets-if-then-formula-what-it-is-and-how-to-use-it>

Google Workspace Tutorials

### [Google Sheets If Then Formula – What it is and how to use it](https://www.saperis.io/blog/google-sheets-if-then-formula-what-it-is-and-how-to-use-it)

Google Sheets If Then formula allows us to react in two different ways depending on if something is true or false. Learn how to use this formula now!

 Admin  May 28, 2020

<https://www.saperis.io/blog/what-is-google-apps-script>

Google Workspace Tutorials

### [What is Google Apps Script? \[Comprehensive Explanation\]](https://www.saperis.io/blog/what-is-google-apps-script)

What is Google Apps Script? It's a cloud-based scripting platform developbed by Google. With Apps Script you can automate Google services.

 Admin  Oct 31, 2020

### Google Workspace Blog

Don't want to miss any of our blog posts about Google Workspace? Then go ahead and sign up!

 

![saperis logo white](https://www.saperis.io/hubfs/saperis%20logo%20white.png)

### Product

- [Product](https://www.saperis.io/products)

### About us

- [About us](https://www.saperis.io/about)

### Blog

- [Blog](https://www.saperis.io/blog)

© 2023 Company All rights reserved [Privacy Policy](https://www.saperis.io/privacy-policy)

[Powered by Atlas - a B2B SaaS HubSpot theme](https://www.kalungi.com/atlas-hubspot-theme-for-b2b-saas-software)

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Admin",
    "url" : "https://www.saperis.io/blog/author/admin"
  },
  "dateModified" : "2023-01-11T08:24:54.492Z",
  "datePublished" : "2020-11-26T14:01:00.000Z",
  "headline" : "How to Copy a Row to another Sheet with Google Apps Script » saperis",
  "image" : [ "https://www.saperis.io/hubfs/Imported_Blog_Media/how-to-copy-a-row-to-another-sheet-with-google-apps-script.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://www.saperis.io/blog/how-to-copy-a-row-to-another-sheet-with-google-apps-script",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.saperis.io/hubfs/logo%20saperis%200.5x-1.png"
    },
    "name" : "SAPERIS CONSULTING S.L."
  }
}
```