Tom Sawkins
Tom Sawkins

Reputation: 361

Copy a range of a row instead of the entire row - APPS SCRIPT

I have the below script that copies an entire row of data to another sheet when condition met.I use checkboxes and whichever checkbox has been checked - the entire row is copied to another sheet.

 function onEdit(e) {
 var sh=e.range.getSheet();
 if(sh.getName()!='TOP UP NEEDED')return
 if(e.range.columnStart==18 && e.value=="TRUE") {
 var tsh=e.source.getSheetByName("ONLINE RELOCATION");
 var trg=tsh.getRange(tsh.getLastRow()+1,1);
 sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()).copyTo(trg);
 }}

I would like however if it could copy say B:H of that row that have been selected

Hope that is possible

Thanks in advance

Upvotes: 0

Views: 48

Answers (1)

Benoît Wéry
Benoît Wéry

Reputation: 862

Sure, you would simply need to alter

sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()).copyTo(trg);

and make it

sh.getRange(e.range.rowStart,2,1,7).copyTo(trg);

(see https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column,-numrows,-numcolumns)

Upvotes: 2

Related Questions