Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Add row in google Spreadsheet with javascript

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.

var Sheet1 = SpreadSheet.getSheetByName("Sheet1");
  
  var LastRow = Sheet1.getLastRow();

  
  Sheet1.getRange(LastRow+1, 1).setValue(name);

Any solutions to add a line and paste the values ​​in 2:2 and the old values ​​underneath?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use insertRowAfter()

Script:

function myFunction() {
  var SpreadSheet = SpreadsheetApp.getActiveSpreadsheet();
  var Sheet1 = SpreadSheet.getSheetByName("Sheet1");
  // insert row at row 2, moving all rows below the first row down a single row
  Sheet1.insertRowAfter(1);
  var name = [['1.5']];
  // then write data at row 2
  Sheet1.getRange(2, 1, name.length, name[0].length).setValues(name);
}

Sample data:

enter image description here

Output:

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!