I need a simple script for Google sheet which will automatically daily will do simple task - copy a 3 cell's values and paste into another 3 cells as a plain text.
Is anyone can help me?
Assuming your spreadsheet page is named PAGE 1
and you want to copy the data from A1
to A3
and paste it into the same PAGE 1
in cells B1
through B3
, this is the script to use:
function MyFunction() {
var ss = SpreadsheetApp.getActive();
ss.getRange('Page 1!A1:A3').copyTo(ss.getRange('Page 1!B1:B3'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
To achieve what you want to do. I recommend you to use the Time-driven triggers, which help you to trigger events every "n" time (mins, hours, days). Follow these steps to configure the Time-driven triggers.
1) Go to your Apps Script project
2) Click Edit->Current project's triggers
3) Click "+ Add Trigger"
4) Select :
Select type of time based trigger->Day timer
Select time of day->[Hour you want]
5) Click Save
6) Use this code in your Apps Script project:
// Name this function as "setTimeTrigger"
function setTimeTrigger(){
// Get first sheet in the active Spreadsheet
var ss = SpreadsheetApp.getActive().getSheets()[0];
// Parameters you set
var sourceVals = "A1:A3";
var destination = "B1:B3";
// Copy and paste the values where you want to
ss.getRange(sourceVals).copyTo(ss.getRange(destination));
}
You can learn more about triggers and Spreadsheet Class in the following docs: