How to paste array to row in google sheets?

92 views
Skip to first unread message

Михайло

unread,
Apr 24, 2024, 5:29:49 PM4/24/24
to Google Apps Script Community
Maybe exist some command like in Excel VBA?
Sheets(1).Range("A1").Resize(1, UBound(myarr)) = myarr

Ed Robinson

unread,
Apr 26, 2024, 7:19:24 AM4/26/24
to Google Apps Script Community
Hi Михайло
Are you asking how to paste a range of data into a sheet in a single operation?

Yes you can do this. The data has to be in a multidimensional array - like a matrix.

This sample shows how to paste an array of five values into a row, and also into a column


function sample_on_click() {
var sht = SpreadsheetApp.getActive().getActiveSheet()
var myRow = [[1,2,3,4,5]]
var myColumn = [[1],[2],[3],[4],[5]]

sht.getRange(1,1,1,myRow[0].length).setValues(myRow)
sht.getRange(1,1,myColumn.length,1).setValues(myColumn)

SpreadsheetApp.flush()
}
Reply all
Reply to author
Forward
0 new messages