This is a script that I use on a Google sheet for parsing data that has been pasted from various other software and getting it into the correct format and columns on another sheet. Data is pasted into the "CL" sheet where it is parsed and formatted via formulas on the sheet.
The data is then sent to either just the "Work Log" sheet or both the "Work Log" sheet and "Represented" sheet if cell D15
is set to "Yes"
.
The cells that were changed on sheet "CL" are then deleted and/or changed back to the original values so another entry can be pasted.
Is there a more efficient way to setValue
on each of the cells that need to be changed? Or do I need to do them one at a time, as I have them here?
function SendToWorkLogCL() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("CL");
var sheet2 = ss.getSheetByName("Work Log");
var repsheet = ss.getSheetByName("Representing");
var rep = sheet1.getRange("D15");
var repvalue = rep.getValue();
if (repvalue == 'Yes') {
sheet1.getRange("A2:W2").copyTo(repsheet.getRange(repsheet.getLastRow()+1,1,1,7), {contentsOnly:true});
sheet1.getRange("A2:W2").copyTo(sheet2.getRange(sheet2.getLastRow()+1,1,1,7), {contentsOnly:true});
SpreadsheetApp.getActiveSheet().getRange('A3:B23').setValue('');
SpreadsheetApp.getActiveSheet().getRange('A3').setValue('Ctrl+SHIFT+V');
SpreadsheetApp.getActiveSheet().getRange('D12').setValue('Chargeback');
SpreadsheetApp.getActiveSheet().getRange('D13').setValue('Yes');
SpreadsheetApp.getActiveSheet().getRange('D14:D15').setValue('No');
SpreadsheetApp.getActiveSheet().getRange('D17').setValue('');
SpreadsheetApp.getActiveSheet().getRange('D18').setValue('0');
SpreadsheetApp.getActiveSheet().getRange('D20').setValue('');
SpreadsheetApp.getActiveSheet().getRange('G12:G15').setValue('');
SpreadsheetApp.getActiveSheet().getRange('D16').setFormula("=IF(A2=\"\",\"\",VLOOKUP(E18,'Data Validation'!C2:E204,3,FALSE))");
}else{
sheet1.getRange("A2:W2").copyTo(sheet2.getRange(sheet2.getLastRow()+1,1,1,7), {contentsOnly:true});
SpreadsheetApp.getActiveSheet().getRange('A3:B23').setValue('');
SpreadsheetApp.getActiveSheet().getRange('A3').setValue('Ctrl+SHIFT+V');
SpreadsheetApp.getActiveSheet().getRange('D12').setValue('Chargeback');
SpreadsheetApp.getActiveSheet().getRange('D13').setValue('Yes');
SpreadsheetApp.getActiveSheet().getRange('D14:D15').setValue('No');
SpreadsheetApp.getActiveSheet().getRange('D17').setValue('');
SpreadsheetApp.getActiveSheet().getRange('D18').setValue('0');
SpreadsheetApp.getActiveSheet().getRange('D20').setValue('');
SpreadsheetApp.getActiveSheet().getRange('D16').setFormula("=IF(A2=\"\",\"\",VLOOKUP(E18,'Data Validation'!C2:E204,3,FALSE))");
}
}