I have some check boxes in google sheet, and I need if I checked some of it (1 of pic) then run macro do the next copy specific cells with its formats (2 of pic) and paste it in the cell beside the check box(3 of pic)
CodePudding user response:
You can achieve it by onEdit() trigger.
function onEdit(e) {
var s = e.source.getActiveSheet(), r ;
var shtn=s.getName();
if(shtn=="Sheet4") { //checks that we're on the correct sheet
r = e.range;
var linecol = r.getColumn();
var linerow = r.getRow() ;
//Browser.msgBox(linecol);
if(linecol == 1 ) { //checks the column A
//Browser.msgBox(linecol);
s.getRange('B' linerow).activate();
s.getRange('B3:F3').copyTo(s.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
var colfs=s.getRange("I:J").getFormulas();
//Browser.msgBox(colfs);
for (i=linerow-2; i>2; i--){
if (colfs[i][0]!==""){//chk if there is a formula
//Browser.msgBox(i " --- " colfs[i][0]);
break;
}
}
s.getRange('I' linerow).setValue("=sum(I" (i 1) ":I" (linerow-1) ")") ;
}//chk col
}//chk sheet1
}
If you share a sheet link with public edit rights, you will get the help quickly
Check my sample sheet here
https://docs.google.com/spreadsheets/d/16XwVAF6DqIaREA9Cvxz2IvsON5vFJc0gJjHHPR9ZKH4/edit?usp=sharing
You need to authorize the script