Adds the value below the line created earlier. I’m trying to get me to add a line at “2:2” and put the value on that line, and the other values stay below. The maximum result I got so far was to make the new line erase the old one and paste the new value in the same field.
JavaScript
x
7
1
var Sheet1 = SpreadSheet.getSheetByName("Sheet1");
2
3
var LastRow = Sheet1.getLastRow();
4
5
6
Sheet1.getRange(LastRow+1, 1).setValue(name);
7
Any solutions to add a line and paste the values in 2:2 and the old values underneath?
Advertisement
Answer
Use insertRowAfter()
Script:
JavaScript
1
10
10
1
function myFunction() {
2
var SpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
3
var Sheet1 = SpreadSheet.getSheetByName("Sheet1");
4
// insert row at row 2, moving all rows below the first row down a single row
5
Sheet1.insertRowAfter(1);
6
var name = [['1.5']];
7
// then write data at row 2
8
Sheet1.getRange(2, 1, name.length, name[0].length).setValues(name);
9
}
10