Write multiple rows of data to Google Sheets using Apps Script (2024)

A very common use case when you're working with Apps Script is writing multiple rows of data to a Google Sheets spreadsheet. In this tutorial, I will show you two methods to append multiple rows to a spreadsheet and help you understand which method you should use and why.

Method 1: Append a single row at a time to a Google Sheets spreadsheet using Apps Script (Not recommended 👎)

In the code below, the function writeMultipleRows() appends a single row of data at a time. This is not recommended since it will result in very poor performance. A better approach is to write all rows at once to the spreadsheet. This is called a 'batch operation' or a 'batch write' and is the recommended method for writing large amounts of data to a spreadsheet.

The code uses the appendRow() method of the Sheet object to write a single row of data to the spreadsheet. To append a row, pass an array of values (corresponding to the columns) to the appendRow() method.

For example, the code below appends a row containing two values: First name and Last name.

var row = ["First name", "Last name"];SpreadsheetApp.getActiveSheet().appendRow(row);

Note

The function getMultipleRowsData() generates 1000 rows of test data for the purpose of this tutorial. In your code, you should assign a two-dimensional array of actual data to the variable data in the code below. You can then delete the getMultipleRowsData() function.

//@onlyCurrentDocfunction writeMultipleRows() { var data = getMultipleRowsData(); for(var i = 0; i < data.length; i++) { SpreadsheetApp.getActiveSheet().appendRow(data[i]); }}function getMultipleRowsData() { var data = []; for(var i =0; i < 1000; i++) { data.push([Math.random(), Math.random(), Math.random(), Math.random()]); } return data;}

The video below shows you how inefficient and slow this method is. It is slow even when the number of rows being written is just 1000, which is relatively small.

Method 2: Append multiple rows at once to a Google Sheets spreadsheet using Apps Script (Recommended 👍)

The recommended way to write multiple rows of data to a Google Sheets spreadsheet using Apps Script is by using the setValues() method of a Range object.

The idea is to access the range in the spreadsheet where the data needs to be written and write all of the data to that range at once.

The function writeMultipleRows() in the code below implements this idea. First, we find out the number of existing rows in the spreadsheet using

SpreadsheetApp.getActiveSheet().getLastRow(). Then we add 1 to this value to get the row at which we should begin appending data. Then we access the range based on the size of the two-dimensional array of data that needs to be written to the spreadsheet. The value data.length tells us how many rows need to be written and data[0].length tells us how many columns are in each row.

Once we access the range, we write data to the range using the setValues() method.

Note

Please refer to the following tutorials for more information on working with ranges in Google Sheets using Google Apps Script:

//@onlyCurrentDocfunction writeMultipleRows() { var data = getMultipleRowsData(); var lastRow = SpreadsheetApp.getActiveSheet().getLastRow(); SpreadsheetApp.getActiveSheet().getRange(lastRow + 1,1,data.length, data[0].length).setValues(data);}function getMultipleRowsData() { var data = []; for(var i =0; i < 1000; i++) { data.push([Math.random(), Math.random(), Math.random(), Math.random()]); } return data;}

The video below shows you how fast this method is. All 1000 rows are written to the spreadsheet almost instantaneously. This is because all rows are written in a single batch operation versus one by one. The concept of a batch operation is important to understand when you code to improve the performance of your scripts.

Conclusion

In this tutorial you learned how to efficiently write multiple rows of data to a Google Sheets spreadsheet using Apps Script.

This tutorial also gave you a glimpse into how much more efficient batch operations are when compared to doing things one at a time. Instead of writing rows one at a time, write all rows at once to the spreadsheet using a batch operation. This will improve performance and your users will thank you for making their workflows faster.

Thanks for reading!

Stay up to date

Follow me via email to receive actionable tips and other exclusive content. I'll also send you notifications when I publish new content.

By signing up you agree to the Privacy Policy & Terms.

Have feedback for me?

I'd appreciate any feedback you can give me regarding this post.

Was it useful? Are there any errors or was something confusing? Would you like me to write a post about a related topic? Any other feedback is also welcome. Thank you so much!

Write multiple rows of data to Google Sheets using Apps Script (2024)

FAQs

Write multiple rows of data to Google Sheets using Apps Script? ›

The recommended way to write multiple rows of data to a Google Sheets spreadsheet using Apps Script is by using the setValues() method of a Range object. The idea is to access the range in the spreadsheet where the data needs to be written and write all of the data to that range at once.

How do I write multiple rows in Google Sheets? ›

Insert a row with shortcuts method 1:

While holding “Shift” down, press “↓” one time less than the number of rows you need to insert. For example, if you want to add 5 additional rows, you'll need to press “↓” four times. Press “Ctrl”+”Alt”+“=” (for Windows) or “⌘” + “Option” + “=” (for Mac).

How do I insert 100 rows in Google Sheets? ›

To add 100+ rows to your spreadsheet:
  1. On your spreadsheet, scroll to the bottom.
  2. Next to "more rows at the bottom," enter the number of rows you'd like to add.
  3. Click Add.

How many rows is too many for Google Sheets? ›

The fundamental Google Sheets size limitation is 10,000,000 rows if you only have 1 column (Note: Google Sheets also has a 100MB file size import limit). By default, when a new Google Sheet is opened, it has 26 columns labeled A through Z. Scrolling to the bottom of a new Google Sheet will take the user to row 1000.

How do I combine data from multiple rows in Google Sheets? ›

Right click in the row in which you want to enter more merged data. Click Insert 1 row above. Click in the cell where you want the merged data, Start to type the formula =JOIN(", ", . Click into all of the cells you want to include in the merged data.

How do I auto insert rows in Google Sheets? ›

Insert Mode / Auto-Insert Mode
  1. Click on Keyboard Shortcuts in the Help menu. or CTRL / or ALT SHIFT H then K.
  2. Check that Enable compatible spreadsheet shortcuts is enabled.
  3. Insert Row. Above: CTRL I then R or ALT I then R. Below: CTRL I then B or ALT I then B.
Jan 3, 2023

Can you bulk insert rows in Google Sheets? ›

Hold down the Shift key to select each row. Select Insert 4 rows below. Google Sheets will add four blank rows below your selection.

How do you insert 100 rows at once? ›

For example, to add 100 empty rows, you can select a range of 10 rows, use the inserting rows shortcut to add 10 rows, and then just press F4 or Ctrl + Y ten times to repeat the insertion, resulting in a total of 100 empty rows.

How do I auto sum multiple rows in Google Sheets? ›

Step-by-Step Guide to AUTOSUM
  1. Click on the cell where the total will appear.
  2. Press Alt + = or click on the Σ icon.
  3. Verify the selected range.
  4. Press Enter to apply the Sum Formula.
Feb 10, 2024

How do I fill all rows in Google Sheets? ›

Use autofill to complete a series

Highlight the cells. You'll see a small blue box in the lower right corner. Drag the blue box any number of cells down or across. If the cells form a series of dates or numbers, the series will continue across the selected cells.

Can Google Sheets handle 1 million rows? ›

Google Sheets can handle way more than 100,000 in terms of raw row count. It can handle 10 million rows as long as there's only one column. The more columns you have, the fewer rows you can add.

Is Google Sheets easier than Excel? ›

Google Sheets is more user-friendly and accessible; Excel is more advanced. If you're looking for a basic spreadsheet app at no cost to you, Google Sheets has you covered. If you need more powerful tools for managing and manipulating data and don't mind dropping some cash on a spreadsheet app, Excel may be a better fit ...

Does Google Sheets have unlimited rows? ›

Google Sheets can process 18,278 columns. The upper limit for rows is 40,000. A Google Sheet workbook can have 200 sheets.

How to compile data in Google Sheets? ›

Compile data from separate spreadsheets
  1. In Sheets, open a spreadsheet.
  2. In an empty cell, enter =IMPORTRANGE.
  3. In parenthesis, add the following specifications in quotation marks and separated by a comma*: The URL of the spreadsheet in Sheets. ...
  4. Press Enter.
  5. Click Allow access to connect the 2 spreadsheets.

How to use textjoin in Google Sheets? ›

If you have a list of values in separate cells and you want to combine them into a single cell with a delimiter between each value, you can use TEXTJOIN . For example, to combine a list of names in cells A1:A5 with a comma between each name, you could use the formula: =TEXTJOIN(", ", TRUE, A1:A5) .

How do I add multiple rows in Google Sheets? ›

How to Add Multiple Rows in Google Sheets (Menu Method)
  1. Step 1: Left Click on a Row Number Where you Want to Add Rows. ...
  2. Step 2: Hold the Shift key and click on Additional Rows. ...
  3. Step 3: In the File Menu Click: Insert > Rows Above or Below. ...
  4. Step 4: New rows will appear above the rows you selected.
May 9, 2024

How do I split text into multiple rows in Google Sheets? ›

Split cells by a given position
  1. Select cells with the text you want to split. ...
  2. Click once and you'll see a red line before the characters that will be taken to a new column/row. ...
  3. Once the positions are set, choose whether to split into rows or columns from the drop-down at the bottom:

How do I insert more than one row in Google Docs? ›

How to Add Multiple Rows in Google Sheets (Menu Method)
  1. Step 1: Left Click on a Row Number Where you Want to Add Rows. ...
  2. Step 2: Hold the Shift key and click on Additional Rows. ...
  3. Step 3: In the File Menu Click: Insert > Rows Above or Below. ...
  4. Step 4: New rows will appear above the rows you selected.
May 9, 2024

How do I apply a function to multiple rows in Google Sheets? ›

Grab the fill handle: Click the cell containing the formula, and locate the small blue square (fill handle) in the bottom-right corner of the cell. Drag the fill handle: Click and hold the fill handle, then drag it down to the last cell of the column where you want to apply the formula.

How do I put two rows of text in one cell in Google Sheets? ›

Click a cell that's empty, or double-click a cell that isn't empty. Start typing. Optional: To add another line within a cell, press ⌘ + Enter on a Mac or Ctrl + Enter on Windows. When you're done, press Enter.

Top Articles
How To Set Up Stardew Valley Parental Controls
Top 5 Strategies for Choosing Liquidity Pools
Bleak Faith: Forsaken – im Test (PS5)
Junk Cars For Sale Craigslist
Google Sites Classroom 6X
Boggle Brain Busters Bonus Answers
5 Bijwerkingen van zwemmen in een zwembad met te veel chloor - Bereik uw gezondheidsdoelen met praktische hulpmiddelen voor eten en fitness, deskundige bronnen en een betrokken gemeenschap.
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Gameplay Clarkston
Craigslist Dog Sitter
Southland Goldendoodles
Large storage units
Gfs Rivergate
General Info for Parents
More Apt To Complain Crossword
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
Tcgplayer Store
Buff Cookie Only Fans
Vanessa West Tripod Jeffrey Dahmer
Race Karts For Sale Near Me
Timeforce Choctaw
Rogue Lineage Uber Titles
Hesburgh Library Catalog
Frank Vascellaro
Bridgestone Tire Dealer Near Me
Kokomo Mugshots Busted
Where Do They Sell Menudo Near Me
2016 Honda Accord Belt Diagram
Terrier Hockey Blog
When His Eyes Opened Chapter 2048
Froedtert Billing Phone Number
Citibank Branch Locations In Orlando Florida
Three V Plymouth
Sig Mlok Bayonet Mount
COVID-19/Coronavirus Assistance Programs | FindHelp.org
Cocorahs South Dakota
Myrtle Beach Craigs List
Does Target Have Slime Lickers
Trending mods at Kenshi Nexus
26 Best & Fun Things to Do in Saginaw (MI)
Willkommen an der Uni Würzburg | WueStart
American Bully Puppies for Sale | Lancaster Puppies
Marcel Boom X
Online College Scholarships | Strayer University
Ronnie Mcnu*t Uncensored
Guy Ritchie's The Covenant Showtimes Near Look Cinemas Redlands
Game Like Tales Of Androgyny
Festival Gas Rewards Log In
Dcuo Wiki
Taterz Salad
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 5807

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.