I put together this test:
The function: in the List tab, when you change the name of col B, part of the row is copied to the matching sheet.
What I need is to copy them to separate spreadsheets (one for each employer). Is that possible?
My code:
// http://victorwyee.com/gapps/move-row-on-cell-value-google-spreadsheets/
/**
* Moves row of data to another spreadsheet based on criteria in column 6.
* Each spreadsheet can be a "source" spreadsheet, or the "target" spreadsheet.
* Assumes there as many spreadsheets as there are criteria values, e.g.
* if the criteria are "R", "P", and "D", then there are three spreadsheets
* named "R", "P" and "D".
* Assumes that each spreadsheet has the same structure.
*/
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
var r = SpreadsheetApp.getActiveRange();
// Get the row and column of the active cell.
var rowIndex = r.getRowIndex();
var colIndex = r.getColumnIndex();
// Get the number of columns in the active sheet.
var colNumber = s.getLastColumn();
// Move row based on criteria in column 6, and if row is not the header.
if (colIndex == 2 && rowIndex != 1) {
// Get value from column 6, in the active row.
var status = s.getRange(rowIndex, colIndex).getValue();
// Do nothing if criteria value is not actually changed to something else.
if (s.getName() != status) {
// The target sheet is the one with the same name as the criteria value.
var targetSheet = ss.getSheetByName(status);
var target = targetSheet.getRange(targetSheet.getLastRow() +1, 1);
// Set the range and copy
// s.getRange(rowIndex, 10, 1, colNumber).copyTo(target);
targetSheet.insertRowsAfter(targetSheet.getLastRow(), 1);
s.getRange(rowIndex, 1, 1, 16).copyTo(target);
// s.deleteRow(rowIndex);
}
}
}
Have made some changes so the comments are not updated.