Here is an example of a Google Apps Script function that uses the importRange
function to retrieve data from another sheet:
function myFunction() {
var sourceSheetUrl = 'https://docs.google.com/spreadsheets/d/1234567890abcdefghijklmnopqrstuvwxyz/edit#gid=987654321';
var sourceSheetRange = 'Sheet1!A1:C10';
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var importedRange = SpreadsheetApp.openByUrl(sourceSheetUrl).getRange(sourceSheetRange).getValues();
targetSheet.getRange(1, 1, importedRange.length, importedRange[0].length).setValues(importedRange);
}
In this example, the importRange
function is used to get the values from a range in a sheet specified by sourceSheetUrl
and sourceSheetRange
. The imported range is then copied to Sheet2
in the active spreadsheet using the setValues
method.
Note that this function uses Google Apps Script, which is a scripting language based on Javascript that is used to automate tasks in Google Sheets and other Google apps. To create and run this function, you'll need to open the script editor in Google Sheets (Tools > Script editor), paste in the code, save it, and then run it from the script editor (Run > myFunction).
Asked: 2022-11-23 11:00:00 +0000
Seen: 11 times
Last updated: Jun 19 '22