Brandon
Brandon

Reputation: 117

Is there a function to log data after an importdata() function refreshes?

Let us say I have an importdata function that refreshes every day and returns a table of 10 rows. Is there a function that allows me to log the data of the cells into another part of the workbook? So theoretically after a couple of weeks, I would have historical data automatically.

Upvotes: 1

Views: 47

Answers (1)

Nikko J.
Nikko J.

Reputation: 5533

You can use Google Apps Script to copy and paste data to another sheet and create an Installable Triggers with event source of time-driven that will schedule the execution of script.

Example:

This script will append data from Sheet1 to Sheet2:

Code:

function myFunction() {
  var sh = SpreadsheetApp.getActiveSpreadsheet();
  var sh1 = sh.getSheetByName('Sheet1');
  var sh2 = sh.getSheetByName('Sheet2');
  var data = sh1.getDataRange().getValues();
  sh2.getRange(sh2.getLastRow()+1, 1, data.length, 1).setValues(data);
}

Sheet1:

enter image description here

Sheet2:

enter image description here

Output:

enter image description here

This trigger will run the script every 12MN to 1AM everyday.

Setup

References:

Upvotes: 2

Related Questions