How do I cut and paste source data into a historical tab with App Script?
I currently have multiple tabs with information that is updated once a day. Below is an example of the data that is entered every day.
My goal is to have a script that cuts the data into a log tab that keeps all of the historical information. The log data is structured as follows.
When I run the script the "source" tab would turn blank for the "Code" and "Qty" columns, and "Date" cell. See below for an example. The formula on column "Description" would remain the same.
Please note I have multiple tabs with source data that need to go into the log/historical tab every day.
Thank you in advance for your insights!
Append values to master sheet
function appenddata() {
const ss = SpreadsheetApp.getActive();
const msh = ss.getSheetByName('Master');
const date = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd/MM/yyyy")
ss.getSheets().filter(sh => sh.getName().startsWith('CART')).forEach(sh => {
let vs = sh.getRange(2, 1, sh.getLastRow() - 1, 3).getValues().map(r => {
r.unshift(date);
r.unshift(sh.getName());
return r;
});
msh.getRange(msh.getLastRow() + 1, 1, vs.length, vs[0].length).setValues(vs);
sh.getRange(2,1,sh.getLastRow() - 1, 3).clearContent();
})
}