Advertisement
shoaib-santo

Google Sheet - Completed Tasks

Oct 9th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function moveCompletedTasks() {
  2.   // Define the active sheet and the sheet for completed tasks
  3.   var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  4.   var completedSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Completed Tasks");
  5.  
  6.   // Get the data from the active sheet
  7.   var range = sheet.getDataRange();
  8.   var values = range.getValues();
  9.  
  10.   // Loop through the rows in reverse to avoid skipping rows after deletion
  11.   for (var i = values.length - 1; i >= 1; i--) {
  12.     if (values[i][6] === 'Completed') {
  13.       // Append the completed task row to the "Completed Tasks" sheet
  14.       completedSheet.appendRow(values[i]);
  15.      
  16.       // Delete the row from the original sheet
  17.       sheet.deleteRow(i + 1); // Rows are 1-indexed in Sheets
  18.     }
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement