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

154
Views
app script google sheet getLastRow start from specific column to put data

I need to put data to sheet by app script using getLastRow to put every value under last value:

function addData(name, age, gender) {
      var ss= SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheetByName("Sheet2");
      var currentRow = sheet .getLastRow();
      var nextRow = currentRow + 1;
      sheet .getRange(nextRow,5).setValue(name);
      sheet .getRange(nextRow,6).setValue(age);
      sheet .getRange(nextRow,7).setValue(gender);
}

I have data using before column 5 and the data put after nextRow for column before not column 5

enter image description here

I want to put get the result like that:

enter image description here

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

0

The answer is:

function addData(name, age, gender) {
  var ss= SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Sheet2");
  var startcolumn = tableSheet.getRange("E1:E").getValues();
  var currentRow = startcolumn.filter(String).length
  var nextRow = currentRow + 1;
  sheet .getRange(nextRow,5).setValue(name);
  sheet .getRange(nextRow,6).setValue(age);
  sheet .getRange(nextRow,7).setValue(gender);
}
about 4 years ago · Juan Pablo Isaza Report

0

This will work provided the column you want to insert the value into is "clear" meaning there is no possibility of any old data or unempty cells below the placement point.

Change

var currentRow = sheet .getLastRow(); 

To

var currentRow = sheet.getRange(1,5).getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow();
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!