0
votes

I have a Google sheet trigger that splits the values in Column F when any value in that column gets edited. However I want the script to only split the 'last row', and not all the rows (even the ones above already split)

enter image description here

Which line of code should I add to have the script only split the last edited row in column F and not the entire range? This is my sample so far:

    function Split() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('F2:F50').activate();
  spreadsheet.getRange('F2:F50').splitTextToColumns();
  spreadsheet.getRange('F2:F50').splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.COMMA);
};

Kind regards, Brendon

1

1 Answers

0
votes

I believe your goal as follows.

  • You want to reflect splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.COMMA) to the column "F" of the last row of the active sheet.

In this case, you can use getLastRow().

Modified script:

function Split() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('F2:F50').activate();
  // spreadsheet.getRange('F2:F50').splitTextToColumns();
  // spreadsheet.getRange('F2:F50').splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.COMMA);
  spreadsheet.getRange("F" + spreadsheet.getLastRow()).splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.COMMA);
}

Reference: