Automatic row transfer in Google Sheets using onEdit trigger

I’m trying to set up an automated system in Google Sheets that moves entire rows to another sheet when a specific cell value changes. Previously I used Excel macros with VBA, but now I need to work with Google Apps Script and JavaScript.

The goal is simple: when column G contains “Complete”, the entire row should automatically move from “Task List” sheet to “Finished Tasks” sheet. I found some sample code online and modified it for my needs, but I’m getting an error saying it can’t read the “source” property on line 6.

Since I’m new to JavaScript, I’m not sure what’s causing this issue. Any help would be great!

function onEdit(e) {
  // main sheet: "Task List"
  // destination sheet: "Finished Tasks" 
  // trigger column is G (column 7)
  var workbook = SpreadsheetApp.getActiveSpreadsheet();
  var currentSheet = e.source.getActiveSheet();
  var editedRange = e.source.getActiveRange();
  
  if(currentSheet.getName() == "Task List" && editedRange.getColumn() == 7 && editedRange.getValue() == "Complete") {
    var rowNum = editedRange.getRow();
    var totalCols = currentSheet.getLastColumn();
    var destinationSheet = workbook.getSheetByName("Finished Tasks");
    var newLocation = destinationSheet.getRange(destinationSheet.getLastRow() + 1, 1);
    currentSheet.getRange(rowNum, 1, 1, totalCols).moveTo(newLocation);
    currentSheet.deleteRow(rowNum);
  }
}

Had the same issue moving from Excel VBA to Google Apps Script. This happens because the onEdit trigger doesn’t always populate the event object properly, especially when testing. Don’t rely on e.source - just use SpreadsheetApp.getActiveSpreadsheet() directly. Replace lines 5-6 with: javascript var currentSheet = workbook.getActiveSheet(); var editedRange = currentSheet.getActiveRange(); Also, moveTo() followed by deleteRow() can mess up references. I’ve found it’s more reliable to copy the range values first, then clear the original row. Your approach should work, but if you keep having problems, try copyTo() and clear() methods instead. Test this thoroughly - deleting rows shifts everything and can break your references.

the prob is you’re likely running the onEdit function directly from the script editor. it won’t have the e object in that case. try making an actual change in column G instead. that should resolve the source property issue.

You’re getting that error because the event object is undefined. This usually happens when onEdit runs but the trigger conditions don’t match up right. I’ve hit this same issue moving from VBA to GAS. First, check if your “Task List” sheet name has extra spaces or weird characters - Google Sheets is case-sensitive and picky about exact matches. Also make sure you’re editing exactly column G, not selecting multiple cells by accident. Best fix is adding null checks at the start of your function. Just verify the event object exists before running your logic. Learned this the hard way after getting random errors that were impossible to debug. The moveTo and deleteRow combo should work fine once you fix the trigger issue, but test it on throwaway data first since you can’t undo row deletions.