0

GAS beginner here! I am trying to append a row with values after the last row in my sheet. But one of my columns contains an array formula, so adding a new row with values isn't working correctly. It adds the new row with values at the bottom of the sheet(row 1514, the last row with values in my sheet is row 5).

I got this code below from a tutorial, the code is supposed to fix the issue but it's not working, I am also not sure what the code actually means, particularly, the if statement. I would appreciate if anyone can explain the code below or help me with a code to solve my problem.

function lastRow(col){
 const ss = SpreadsheetApp.getActiveSpreadsheet();
 const optionsSheet = ss.getSheetByName('Options');
 const lastRow = optionsSheet.getMaxRows();
 const range = optionsSheet.getRange(1,col,lastRow).getValues();
 for(i = lastRow-1; i>0; i--){
 console.log(i + 1)

 if(range[i][0]){
   return i+1
 }
 }

}
Chi Resha
  • 25
  • 3

0 Answers0