TransWikia.com

postEdit functions getting range

Web Applications Asked by Gavin Martin on December 23, 2021

Does anyone know how I can change the below function to postEdit rather than onEdit?

I am trying to set this in an autoSort function so that the sheet will be edited only after all values in an inline row, in columns A-F, have been entered rather than been edited straight after values in only column A have been entered?

function onEdit(event) {
  var editedCell;

  activeSheet = SpreadsheetApp.getActiveSheet();
  editedCell = activeSheet.getActiveCell();

  if (editedCell.getColumn() == SORT_COLUMN_INDEX) {
    autoSort(activeSheet);
  }
}

One Answer

Google Apps Script hasn't a postEdit trigger but you can achieve the result you are looking for by using JavaScript conditions.

First, some basic tips,

  1. always use var to declare your variables otherwise they will be declared on the global scope and this could lead to some problems.
  2. make use of the event properties, in this case, instead of getActiveCell() use e.range to get the edited Range object.

The following onEdit function is triggered every time a user makes an edit to the spreadsheet. The autosort function is called, when NOT all values of the corresponding row from A to F are filled up, otherwise it is not.

function onEdit(e){
  if(e.columnStart > 6) return; // If the edited range is on column 7 or beyond, do nothing
  // Check if all the cells in the row are already filled up
  var sheet = e.range.getParent();
  var currentRecord = sheet.getRange(e.rowStart,1,6).getValues()[0];
  var recordComplete = currentRecord.every(function(value){ return value !== ''});
  if(recordComplet){
    // Call the autosort function
      autosort(sheet);
  } else {
    // Do nothing
  }
}

Answered by Rubén on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP