I have about 20 rows in 5 different sheets and I would like the row to copy to a separate sheet once I check the checkbox. I would like the rows to remain in its source sheet when the row is copied.
I found code that copies the entire row over the separate sheet and then copies the row back once it's un-checked, but it obviously needs tweaking to be applicable to my scenario. Here it is:
function onEdit(event) {
// assumes source data in sheets named Brushed Nickel, Chrome, Matte Black, Brass/Gold, Tile and Paint
// target sheet of move to named Desing Specs
// getColumn with check-boxes is currently set to column 11 or K
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Brushed Nickel", "Chrome", "Matte Black", "Brass/Gold", "Tile and Paint" && r.getColumn() == 11 && r.getValue() == true) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Desing Specs");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
} else if(s.getName() == "Desing Specs" && r.getColumn() == 11 && r.getValue() == false) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Brushed Nickel", "Chrome", "Matte Black", "Brass/Gold", "Tile and Paint");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
Screen Shot:
Can someone please help?
Thank you in advance!
function onEdit(e) {
var s = e.range.getSheet();
var shts=["Brushed Nickel", "Chrome", "Matte Black", "Brass/Gold", "Tile and Paint"];
if(shts.indexOf(s.getName()!=-1) && e.range.columnStart==11 && e.value == "TRUE") {
var targetSheet=e.source.getSheetByName("Design Specs");
var target=targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(e.range.rowStart, 1, 1, s.getLastColumn()).copyTo(target);
}
}
Related
I need some assistance please. I have a spreadsheet that moves data from one sheet(JDE worklist) to the next (Printed) by clicking the textbox next to the row to be moved. When the tickbox is un-ticked after its moved the first time it moves it to a final sheet (PrintedArchive). This part works fine.
The problem is that I need a static date stamp next to the row once it gets moved to the next sheet as to capture start and end dates. The date can be added to column BE.
If I try and add a separated script to add a date stamp the script for moving the data stops functioning. So is there a way to incorporate this into the script that moves the data?
Please note that don't have much experience and I'm still learning and would really appreciate the help.
This is the script im currently using to move the data
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "JDE Worklist" && r.getColumn() == 1 && r.getValue() == true) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Printed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
} else if(s.getName() == "Printed" && r.getColumn() == 1 && r.getValue() == false) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("PrintedArchive");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
Sample sheet
Try this:
function onEdit(e) {
e.source.toast("Entry");
const s = e.range.getSheet();
if (s.getName() == "JDE Worklist" && e.range.columnStart == 1 && e.value == "TRUE") {
var tsh = e.source.getSheetByName("Printed");
var trg = tsh.getRange(tsh.getLastRow() + 1, 1);
s.getRange(e.range.rowStart, 1, 1, s.getLastColumn()).moveTo(trg);
tsh.getRange("BE" + e.range.rowStart).setValue(new Date());
s.deleteRow(e.range.rowStart);
} else if (s.getName() == "Printed" && e.range.columnStart == 1 && e.value == "FALSE") {
var tsh = e.source.getSheetByName("PrintedArchive");
var trg = tsh.getRange(tsh.getLastRow() + 1, 1);
s.getRange(e.range.rowStart, 1, 1, s.getLastColumn()).moveTo(trg);
tsh.getRange("BE" + e.range.rowStart).setValue(new Date());
s.deleteRow(e.range.rowStart);
}
}
function onEdit(event) {
// assumes source data in sheet named Backorder LIST
// target sheet of move to named Completed
// getColumn with check-boxes is currently set to column 1 or A
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Backorder LIST" && r.getColumn() == 1 && r.getValue() == true) {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Completed");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
I am having trouble finding a way to move only the values to COMPLETED sheet. Anytime I change .moveTo(target); to .copyTo(target, {contentsOnly: true}); the script fails. Any suggestions would be appreciated. Thank you!
Move values only
function onEdit(e) {
var sh = e.range.getSheet();
if(sh.getName() == "Backorder LIST" && e.range.columnStart == 1 && e.value == "TRUE") {
var tsh = e.source.getSheetByName("Completed");
let vs = sh.getRange(e.range.rowStart, 1, 1, sh.getLastColumn()).getDisplayValues();
tsh.getRange(tsh.getLastRow() + 1, 1, vs.length, vs[0].length).setValues(vs);
sh.deleteRow(e.range.rowStart);
}
}
I have the script below that only works for the first condition. I can switch the conditions order and then the top one will work but not the bottom. Any ideas why?
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Master" && r.getColumn() == 16 && r.getValue() == "Yes") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Complete");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Master" && r.getColumn() == 16 && r.getValue() == "No") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Late");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
}
You can only have one active onEdit(e) simple trigger in a script project. To move rows based on two sets of criteria, you will need to combine the two functions into one.
I would recommend that you use a tried and tested solution such as the moveRowsFromSpreadsheetToSpreadsheet_ script. The code is almost 800 lines long so it is impractical to quote here, but it is simple enough to configure using the parameters section.
My first task was to move data from one sheet to another when a certain entry is made in a certain column. That I did successfully taking help from online sources.
The next task is to add a timestamp to the now moved data(in target sheet). I have tried multiple ways to do that but it's not working at all. I have added my code below, what am I doing wrong?
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Task" && r.getColumn() == 4 && r.getValue() == "Done") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("DoneTask");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
}
else if (s.getName() == "DoneTask" && r.getColumn() == 4 && r.getValue() == "Done")
{var nextCell = r.offset(0, 4);
nextCell.setValue(new Date());
}
}
I think it's because the active sheet is still the "Task" sheet and so the elseif is not working, but I don't know how to verify it.
I don't really see why you would put this in a an else if. Seems like you want to stamp the date when the if statement runs?
Try this.
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Task" && r.getColumn() == 4 && r.getValue() == "Done") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("DoneTask");
var lr = targetSheet.getLastRow();
var target = targetSheet.getRange(lr +1 , 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
targetSheet.getRange(lr + 1, numColumns +1).setValue(new Date());
}
}
I want to add a script that moves a row to another tab if a column isn"t Blank
Here is the script i am using. The "NOT BLANK" is the part i need to figure out. i understand how to move it if it has a specific value but want to know how to get it to move if it has ANY text.
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Current" && r.getColumn() == 1 && r.getValue() == "NOT BLANK") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Complete");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target); s.deleteRow(row);
}
}
if the targeted column isn't blank to move the row to a second tab
Change this line:
if(s.getName() == "Current" && r.getColumn() == 1 && r.getValue() == "NOT BLANK")
To this:
if(event.range.getSheet().getName()=="Current" && event.range.columnStart==1 && event.value.length>0)
This is what I came up with after playing with it a bit.
function onEdit(e) {
var ss=e.source;
var rg=e.range;
var sh=rg.getSheet();
var col=rg.columnStart;
if(sh.getName()=="Sheet46" && col==1 && e.value.length>0) {
var row=rg.rowStart;
var numColumns = sh.getLastColumn();
var targetSheet = ss.getSheetByName("Sheet50");
var target=targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sh.getRange(row, 1, 1, numColumns).moveTo(target);
sh.deleteRow(row);
}
}