With the excellent help of this site I was able to get my onFormSubmit
working.
However I need the same thing to happen on another sheet only it has to happen after a cell has been assigned one of two (potentially more) names.
I have a dummy Form feeding a dummy Spreadsheet with 3 sheets, those being "Luke" "Luke2" "James".
With onFormSubmit
I have it working that if the responses contain "Luke" in Column B
then the info is copied over to sheet "Luke2". This works great, but I want to be able to change the responses in column D
to "James" and have the same set of responses copied over to the sheet names James. As you can imagine I'm trying to have work assigned after information is submitted.
I've tried various code that I've found here but none of it seems to take so I'm leaving it here:
function onFormSubmit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var values = sheet.getDataRange().getValues();
var row = event.range.getRow();
if (values[row-1][1] == 'Luke') {
var targetSheet = ss.getSheetByName('Luke2');
var lastRow = targetSheet.getLastRow();
var targetRange = targetSheet.getRange(lastRow+1, 1, 1, values[0].length);
targetRange.setValues([values[row-1]]);
}
}
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var values = sheet.getDataRange().getValues();
var row = event.range.getRow();
if(values[row-1][3] == 'James' && s.getSheetName == 'Luke') {
var targetSheet = ss.getSheetByName('James');
var lastRow = targetSheet.getLastRow();
var targetRange = targetSheet.getRange(lastRow+1, 1, 1, values[0].length);
targetRange.setValues([values[row-1]]);
}
}
To summarise: the top half works it's the onEdit
that doesn't work.
The if statement is:
if(values[row-1][3] == 'James' && s.getSheetName == 'Luke') { then targetRange.setValues([values[row-1]]); } }
Best Answer
After spending every waking moment working on this and now much more since I have answered this question and I m sorry it took a while to update. here's where I have left off. it's clunky but functional: