I found a script on the Internet and am trying to alter it a little to fit my needs. But stumbled upon a problem. The script takes a list of bookmarks from the drop down menu and if you write OK in the next cell, then it transfers the line to the selected bookmark. I want to confirm today's date.
Copy of the sheet. Also here some diffeent.
var actionCol = 7;
var nameCol = 6;
https://docs.google.com/spreadsheets/d/1P9avWP8i5Z4KA4zt3EoUZNbgMKeXwnOYKsgCG2_vSLE/edit?usp=sharing
/**
* Moves row of data to another spreadsheet based on criteria in column 6 to sheet with same name as the value in column 4.
*/
function onEdit(e) {
// see Sheet event objects docs
// https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events
var ss = e.source;
var s = e.range.getSheet();
var r = e.range;
// to let you modify where the action and move columns are in the form responses sheet
var actionCol = 10;
var nameCol = 9;
// 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.
// -1 to drop our action/status column
var colNumber = s.getLastColumn()-1;
// if our action/status col is changed to ok do stuff
if (e.value == "ok" && colIndex == actionCol) {
// get our target sheet name - in this example we are using the priority column
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
// if the sheet exists do more stuff
if (ss.getSheetByName(targetSheet)) {
// set our target sheet and target range
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
// get our source range/row
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
// new sheets says: 'Cannot cut from form data. Use copy instead.'
sourceRange.copyTo(targetRange);
// ..but we can still delete the row after
s.deleteRow(rowIndex);
// or you might want to keep but note move e.g. r.setValue("moved");
}
}
}
If I understand you correctly, you want to cut & paste the edited row if:
The edited column is G, and the value is a Date corresponding to today.
The corresponding name in column F refers to the name of an existing sheet.
In order to check that the two dates correspond to the same day, you can compare the values returned by getDate(), getMonth() and getFullYear(), as in this function (credits to Pointy):
function sameDay(d1, d2) {
return d1.getFullYear() === d2.getFullYear() &&
d1.getMonth() === d2.getMonth() &&
d1.getDate() === d2.getDate();
}
Then, you can call this in your main function:
function onEdit(e) {
var ss = e.source;
var s = e.range.getSheet();
var r = e.range;
var value = r.getValue();
var actionCol = 7;
var nameCol = 6;
var rowIndex = r.getRow();
var colIndex = r.getColumn();
var colNumber = s.getLastColumn();
if (value instanceof Date && colIndex == actionCol) {
var today = new Date();
if (sameDay(value, today)) {
var targetSheetName = s.getRange(rowIndex, nameCol).getValue();
var targetSheet = ss.getSheetByName(targetSheetName);
if (targetSheet) {
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1);
sourceRange.copyTo(targetRange);
s.deleteRow(rowIndex);
}
}
}
}
Try it this way:
function onEdit(e) {
var ss = e.source;
var s = e.range.getSheet();
var r = e.range;
var actionCol = 10;
var nameCol = 9;
var rowIndex = r.rowStart;
var colIndex = r.columnStart;
var colNumber = s.getLastColumn()-1;
const dt=new Date(e.range.offset(0,n));//you add the column offset
const dtv=new Date(dt.getFullYear(),dt.getMonth(),dt.getDate()).valueOf();
const td=new Date();
const tdv=new Date(td.getFullYear(),td.getMonth(),td.getDate()).valueOf();
if (e.value == "ok" && colIndex == actionCol && dtv==tdv) {
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
var tSh = ss.getSheetByName(targetSheet);
if (tSh) {
var targetRange = tSh.getRange(tSh.getLastRow()+1, 1, 1, colNumber);
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
sourceRange.copyTo(targetRange);
s.deleteRow(rowIndex);
}
}
}
Related
i found this great formula that works so great on my need, sorry i forgot it original source
The Original Code is move the entire Row if it found "X" on Columns 21 and copy the entire row to sheet with same name as col 22 and delete the Entire row
1st Question,
instead the delete entire row, i need it only to clear certains Columns, for example it only clear content Columns 3, 4, 10 and 12 only << Solved thanks to idfurw
2nd Question,
how to lock this script to only a certain sheet?
here the new script base on update from idfurw
Main Script
function onEdit(e) {
// see Sheet event objects docs
// https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events
var ss = e.source;
var s = e.range.getSheet();
if (s.getName() == 'Form');
var r = e.range;
// to let you modify where the action and move columns are in the form responses sheet
var actionCol = 21;
var nameCol = 22;
// 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.
// -1 to drop our action/status column
var colNumber = s.getLastColumn()-1;
// if our action/status col is changed to ok do stuff
if (e.value == "XX" && colIndex == actionCol) {
// get our target sheet name - in this example we are using the priority column
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
// if the sheet exists do more stuff
if (ss.getSheetByName(targetSheet)) {
// set our target sheet and target range
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
// get our source range/row
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
// new sheets says: 'Cannot cut from form data. Use copy instead.'
sourceRange.copyTo(targetRange);
// ..but we can still delete the row after
const cols = [6, 7, 8, 12,14,16,17,19,20,21];
for (const col of cols) {
s.getRange(rowIndex, col).clearContent();
}
// or you might want to keep but note move e.g. r.setValue("moved");
}
}
}
Time Stamp Script
function onEdit(event)
{
var timezone = "GMT+7";
var time_format = "dd-MM-yyyy"; // Timestamp Format.
var updateColName = "Pasien";
var timeStampColName = "Tgl Keluar";
var sheet = event.source.getSheetByName('Form'); //Name of the sheet where you want to run this script.
var actRng = event.source.getActiveRange();
var editColumn = actRng.getColumn();
var index = actRng.getRowIndex();
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
var dateCol = headers[0].indexOf(timeStampColName);
var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
if (dateCol > -1 && index > 1 && editColumn == updateCol)
{ // only timestamp if 'Last Updated' header exists, but not in the header row itself!
if (sheet.getRange(index, updateCol).isBlank()) {
sheet.getRange(index, dateCol + 1).clearContent();
}
else
var cell = sheet.getRange(index, dateCol + 1);
var date = Utilities.formatDate(new Date(), timezone, time_format);
cell.setValue(date);
}
}
Remove this line to disable deleting row:
s.deleteRow(rowIndex);
Replace with the following to clear content of specified cols:
const cols = [3, 4, 10, 12];
for (const col of cols) {
s.getRange(rowIndex, col).clearContent();
}
To limit the function to a particular sheet:
var s = e.range.getSheet();
/* add it after the above line */
if (s.getName() !== 'Name of sheet') { return; }
Need help on combining these two script. Im totally newbie in this thing. They are
Main.gs
whenput 'XX' on U Column (21st col) then it copy the whole row to a sheet with same name as V Column (22nd col). Then it delete certain columns (for example 6, 7, 8, 12,14,16,17,19,20,21)
function onEdit(e) {
var ss = e.source;
var s = e.range.getSheet();;
var r = e.range;
// to let you modify where the action and move columns are in the form responses sheet
var actionCol = 21;
var nameCol = 22;
// 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.
// -1 to drop our action/status column
var colNumber = s.getLastColumn()-1;
// if our action/status col is changed to ok do stuff
if (e.value == "XX" && colIndex == actionCol) {
// get our target sheet name - in this example we are using the priority column
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
// if the sheet exists do more stuff
if (ss.getSheetByName(targetSheet)) {
// set our target sheet and target range
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
// get our source range/row
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
// new sheets says: 'Cannot cut from form data. Use copy instead.'
sourceRange.copyTo(targetRange);
// ..but we can still delete the row after
const cols = [6, 7, 8, 12,14,16,17,19,20,21];
for (const col of cols) {
s.getRange(rowIndex, col).clearContent();
}
// or you might want to keep but note move e.g. r.setValue("moved");
}
}
}
and
TimeStamp.gs
when type a word at "Pasien" Col, at the same row it will add date to "Tgl Keluar" col and when delete that word, it also clear content
function onEdit(event)
{
var timezone = "GMT+7";
var time_format = "dd-MM-yyyy"; // Timestamp Format.
var updateColName = "Pasien";
var timeStampColName = "Tgl Keluar";
var sheet = event.source.getSheetByName('Form'); //Name of the sheet where you want to run this script.
var actRng = event.source.getActiveRange();
var editColumn = actRng.getColumn();
var index = actRng.getRowIndex();
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
var dateCol = headers[0].indexOf(timeStampColName);
var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
if (dateCol > -1 && index > 1 && editColumn == updateCol)
{ // only timestamp if 'Last Updated' header exists, but not in the header row itself!
if (sheet.getRange(index, updateCol).isBlank()) {
sheet.getRange(index, dateCol + 1).clearContent();
}
else
var cell = sheet.getRange(index, dateCol + 1);
var date = Utilities.formatDate(new Date(), timezone, time_format);
cell.setValue(date);
}
}
This my combined onEdit
but i still dont understand about nested
function onEdit(event) {
first(event);
second(event);
}
function first(event)
{
var ss = e.source;
var s = e.range.getSheet();;
if (s.getName() !== 'Form')
var r = e.range;
// to let you modify where the action and move columns are in the form responses sheet
var actionCol = 21;
var nameCol = 22;
// 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.
// -1 to drop our action/status column
var colNumber = s.getLastColumn()-1;
// if our action/status col is changed to ok do stuff
if (e.value == "XX" && colIndex == actionCol) {
// get our target sheet name - in this example we are using the priority column
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
// if the sheet exists do more stuff
if (ss.getSheetByName(targetSheet)) {
// set our target sheet and target range
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
// get our source range/row
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
// new sheets says: 'Cannot cut from form data. Use copy instead.'
sourceRange.copyTo(targetRange);
// ..but we can still delete the row after
const cols = [6, 7, 8, 12,14,16,17,19,20,21];
for (const col of cols) {
s.getRange(rowIndex, col).clearContent();
}
// or you might want to keep but note move e.g. r.setValue("moved");
}
}
}
function second(event)
{
var timezone = "GMT+7";
var time_format = "dd-MM-yyyy"; // Timestamp Format.
var updateColName = "Pasien";
var timeStampColName = "Tgl Keluar";
var sheet = event.source.getSheetByName('Form'); //Name of the sheet where you want to run this script.
var actRng = event.source.getActiveRange();
var editColumn = actRng.getColumn();
var index = actRng.getRowIndex();
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
var dateCol = headers[0].indexOf(timeStampColName);
var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
if (dateCol > -1 && index > 1 && editColumn == updateCol)
{ // only timestamp if 'Last Updated' header exists, but not in the header row itself!
if (sheet.getRange(index, updateCol).isBlank()) {
sheet.getRange(index, dateCol + 1).clearContent();
}
else
var cell = sheet.getRange(index, dateCol + 1);
var date = Utilities.formatDate(new Date(), timezone, time_format);
cell.setValue(date);
}
}
The third code would be the simplest solution in case it complete within the time limit.
Otherwise, you need to optimize the code by:
replacing call of SpreadsheetApp by event object
removing duplicates among the two child functions
using if, boolean (flag), return to minimize executions
You need to know you code well in other to do either of these.
I dare not rewrite the code entirely. Just in order to make it a bit faster I'd propose to change this lines (in the third example):
const cols = [6, 7, 8, 12,14,16,17,19,20,21];
for (const col of cols) {
s.getRange(rowIndex, col).clearContent();
}
to this:
// cols to clean
const cols = [6, 7, 8, 12, 14, 16, 17, 19, 20, 21];
// get an array from the row
var row_to_clean = s.getRange(rowIndex, 6, rowIndex, 21).getValues();
// clean the array
for (let c of cols) row_to_clean[0][c-6] = ''; // col 6 is array[0][0]
// set values of the array back on the row
s.getRange(rowIndex, 6, rowIndex, 21).setValues(row_to_clean);
It will reduce calls to the server from 10 clearContents() to 2 getValues() + setValues() for every edited row.
here is my code in google script:
function Send(){
Browser.msgBox("Send");
}
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var lr = sheet.getLastRow();
var dataRange = sheet.getRange(startRow, 1, lr-1, 6);
var data = dataRange.getValues();
for (var i = 0; i < data.length; i++) {
var row = data[i];
var name = row[0];
var emailAddress = row[1];
var date = row[2];
var city = row[3];
var status = row[6];
if (emailAddress.match('#') === null){
continue;
};
var subject = row[4];
var message = "Hey " + name + ", welcome in the team " + row[5];
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(i+2,7).setValue("Sent");
}
}
Until here everything works fine. I would like then that when "Sent" appears in the 7th column, that the whole row where "Sent" is in, is moved to another tab.
function onEdit(e) {
var ss = e.source;
var s = ss.getActiveSheet();
var r = e.range;
var actionCol = 7;
var nameCol = 7;
var rowIndex = r.getRowIndex();
var colIndex = r.getColumnIndex();
var colNumber = s.getLastColumn()-1;
if (e.value == "Sent" && colIndex == actionCol) {
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
if (ss.getSheetByName("Welcome")) {
var targetSheet = ss.getSheetByName("Done");
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
sourceRange.copyTo(targetRange);
s.deleteRow(rowIndex);
}
}
}
**If I manually write "Sent" in the 7th column, the row is moved to the other sheet. But when I run the first function and that "Sent" appears in that column, the onEdit function doesn't work.
So basically both functions work but not together at the same time.
Does someone know a fix for this?**
Issues:
You are trying to trigger an onEdit function via a script but that's not how triggers work. The official documentation states the following:
The onEdit(e) trigger runs automatically when a user changes the value
of any cell in a spreadsheet.
Namely, onEdit triggers are activated only by user actions, not by scripts nor formulas.
You don't need a separate function to check if the value is Sent and then delete the row with another function. After the email is sent you can move the data and delete the row, all within the same function.
Last but not least, when deleting rows iteratively we change the structure of the sheet and therefore the data input does not match the updated structure. To alleviate this issue, we can store the indexes of the rows we want to delete in an array, and then using that array delete the rows backwards.
Solution:
Assuming your codes work separately, this should also work:
function myFunction() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Welcome");
var targetSheet = ss.getSheetByName("Done");
var startRow = 2;
var lr = sheet.getLastRow();
var dataRange = sheet.getRange(startRow, 1, lr-1, 6);
var data = dataRange.getValues();
var colNumber = sheet.getLastColumn()-1;
var delRows = [];
for (var i = 0; i < data.length; i++) {
var row = data[i];
var name = row[0];
var emailAddress = row[1];
var date = row[2];
var city = row[3];
var status = row[6];
if (emailAddress.match('#') === null){
continue;
};
var subject = row[4];
var message = "Hey " + name + ", welcome in the team " + row[5];
MailApp.sendEmail(emailAddress, subject, message);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
var sourceRange = sheet.getRange(i+startRow, 1, 1, colNumber);
sourceRange.copyTo(targetRange);
delRows.push(i+startRow);
}
// delete rows in reverse order
delRows.reverse().forEach(ri=>{sheet.deleteRow(ri)});
}
you don't need the onEdit function anymore so you can delete it.
I am trying to copy a row over to a new sheet multiple times (based on user response).
After the row has been copied over x number of times, it should move to another sheet and then be removed from the original sheet.
I have it almost working but the while() loop will only subtract from the active cell once in row z and then just keeps repeating.
I would appreciate any help. Here is what I have:
function dupLines()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = SpreadsheetApp.getActiveSheet();
var r = SpreadsheetApp.getActiveRange();
var POStatus = ss.getSheetByName("PO STATUS");
var awarded = ss.getSheetByName("AWARDED");
var cell = s.getCurrentCell();
var cellValue = cell.getValue();
function getTimeStamp()
{
var now = new Date();
return ((now.getMonth() + 1) + '/' + (now.getDate()) + '/' + now.getFullYear() );
}
while (cellValue > '0')
{
POStatus.insertRows(19,1);
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetPO = POStatus.getRange("A19");
s.getRange(row, 1, 1, numColumns).copyTo(targetPO);
POStatus.getRange("X19").setValue(getTimeStamp());
cell.setValue(cellValue - 1);
}
awarded.insertRows(19,1);
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetAwd = awarded.getRange("A19");
s.getRange(row, 1, 1, numColumns).moveTo(targetAwd);
awarded.getRange("X19").setValue(getTimeStamp());
s.deleteRow(row);
}
******************* UPDATE ********************
This is what I have that is now working. I am sure it can be simplified?
function onOpen(e){
SpreadsheetApp.getUi().createMenu('QUEUE MENU')
.addItem('Create POs', 'CreatePOs')
.addSeparator()
.addItem('Sidebar Queue', 'openSidebar')
.addToUi();
}
function CreatePOs() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = SpreadsheetApp.getActiveSheet();
var r = SpreadsheetApp.getActiveRange();
var POStatus = ss.getSheetByName("PO STATUS");
var awarded = ss.getSheetByName("AWARDED");
if(s.getName() == "QUEUE" && r.getColumn() == 22 && r.getValue() == true) {
userInput();
dupLines();
moveToAwarded();
}
else
{
Browser.msgBox('Please check box in PO Status column.');
};
}
function userInput() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().offset(0, 4).activate();
var prompt = SpreadsheetApp.getUi().prompt('How many lines do you want to send to PO STATUS?', SpreadsheetApp.getUi().ButtonSet.OK_CANCEL);
if(prompt.getSelectedButton() === SpreadsheetApp.getUi().Button.OK){
value = prompt.getResponseText();
}
spreadsheet.getCurrentCell().setValue(value);
}
function dupLines(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = SpreadsheetApp.getActiveSheet();
var r = SpreadsheetApp.getActiveRange();
var POStatus = ss.getSheetByName("PO STATUS");
var awarded = ss.getSheetByName("AWARDED");
var cell = s.getCurrentCell();
var cellValue = cell.getValue();
function getTimeStamp() {
var now = new Date();
return ((now.getMonth() + 1) + '/' +
(now.getDate()) + '/' +
now.getFullYear() );
}
while (cellValue > 0) {
POStatus.insertRows(19,1);
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetPO = POStatus.getRange("A19");
s.getRange(row, 1, 1, numColumns).copyTo(targetPO);
POStatus.getRange("X19").setValue(getTimeStamp());
cellValue--;
} }
function moveToAwarded() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = SpreadsheetApp.getActiveSheet();
var r = SpreadsheetApp.getActiveRange();
var POStatus = ss.getSheetByName("PO STATUS");
var awarded = ss.getSheetByName("AWARDED");
function getTimeStamp() {
var now = new Date();
return ((now.getMonth() + 1) + '/' +
(now.getDate()) + '/' +
now.getFullYear() );
}
awarded.insertRows(19,1);
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetAwd = awarded.getRange("A19");
s.getRange(row, 1, 1, numColumns).moveTo(targetAwd);
awarded.getRange("X19").setValue(getTimeStamp());
s.deleteRow(row);
}
function openSidebar(){
var html = HtmlService.createHtmlOutputFromFile('Sidebar').setTitle('Queue Quick View');
SpreadsheetApp.getUi().showSidebar(html);
}
One of the problems (and there may be others) that I can spot is in:
cell.setValue(cellValue - 1); // Changes the value in the cell but not in the script
This changes the value in the active cell. But it does not change the value of the variable cellValue.
Try this while-loop instead:
while (cellValue > '0')
{
POStatus.insertRows(19,1);
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetPO = POStatus.getRange("A19");
s.getRange(row, 1, 1, numColumns).copyTo(targetPO);
POStatus.getRange("X19").setValue(getTimeStamp());
cellValue--; // Reduce value by 1
cell.setValue(cellValue); // Set new value in cell
}
A few other suggestions that may help:
1
while (cellValue > '0') is checking for a string value '0'. It works because alphabetically, all positive numbers are greater than 1. But strictly speaking you want while (cellValue > 0)
2
cell.setValue(cellValue); has cosmetic value, i.e. it updates the cell. But the updated value is not used in the script.
Best practices suggest not making unnecessary calls to the sheet. So you could do without that line and have the script run a bit faster.
My sheet is getting data from form responses. I have multiple tabs for the different request types. Currently when the form is submitted, it comes to the main tab and I manually change the column "status" Column 7 to "Pending Assignment" and using the below script to it sends to the corresponding tab. Is there a way to automate this? Or as the request are coming in move to tabs based on what is in column 4 (request type)?
function myEdit(e){
var ss = e.source;
var s = ss.getActiveSheet();
var r = e.range;
var actionCol = 7;
var nameCol = 4;
var rowIndex = r.getRowIndex();
var colIndex = r.getColumnIndex();
var colNumber = s.getLastColumn();
if ((e.value == "Pending Assignment" && colIndex == actionCol)) {
var targetSheet = s.getRange(rowIndex, nameCol).getValue();
if (ss.getSheetByName(targetSheet)) {
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
sourceRange.copyTo(targetRange);
s.deleteRow(rowIndex);
}
}
}
instead of onEdit, you can use onFormResponse trigger.
function onFormResponse() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formsheet = ss.getSheetByName("Form Responses 1");
var lastrow = formsheet.getLastRow();
var actionCol = 7;
var nameCol = 4;
var colNumber = formsheet.getLastColumn();
formsheet.getRange(lastrow, actionCol).setValue("Pending Assignment");
var targetSheet = s.getRange(lastrow, nameCol).getValue();
if (ss.getSheetByName(targetSheet)) {
var targetSheet = ss.getSheetByName(targetSheet);
var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
var sourceRange = formsheet.getRange(lastrow, 1, 1, colNumber);
sourceRange.copyTo(targetRange);
formsheet.deleteRow(lastrow);
}
}