I've got this code to loop through each cell in Column A and check the cell value. If the value matches the if criteria it moves the entire row to the correct Sheet and then replaces the Column A cell with an X. This makes a call to the server for every cell and I'm curious if there is a way for me to optimize it similar to what Google has documented as Best Practices. The Cache service is confusing me.

Here is a copy of the spreadsheet I'm working on. The code has a menu execution under Move Row.

function moveToQA() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var lastRow = sheet.getLastRow();
  var columnNumberToWatch = 1;
  var targetSheet = ss.getSheetByName("QA 👌");

  for( var i = 3; i >= 3; i++ ) {
    var cell = sheet.getRange(i,1);
    var cellValue = cell.getValue();
    if (cellValue == "Captures Sent 📩" || cellValue == "QA In Progress 👌" || cellValue == "Recapture Completed 📷") {
      var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
      sheet.getRange(cell.getRow(), 1, 1, sheet.getLastColumn()).moveTo(targetRange);
    else if (cellValue != "") {
    else if (cellValue == "" || cell == lastRow) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.