Import Range Apps Script Code for specific cells transfer between 2 work books

Viewed 19

As told by someone here: https://stackoverflow.com/a/65258767/17862862

in this answer, A1 notation dosent seem to work for specified range : var poData = poTab.getDataRange('Incoming Sample!A1:B10').getValues();

But the a1 notation is causing error, without this the code is working fine and importing the whole sheet, which i dont want.

1 Answers

You can use the method SpreadSheet.getSheetByName("Incoming Sample").getRange("A1:B10")

Following Google Documentation for the Sheet.getDataRange() method, it has to be called on a Sheet Object, and does not accept any arguments. It returns all non-empty cells in a Sheet.

That being said, you can get a specific range using the method Sheet.getRange(a1Notation).

So your code would be something like this:

//I am assuming your variable poTab represents the Sheet 'Incoming Sample'
//Please let me know if I am mistaken
var poData = poTab.getRange('A1:B10').getValues();

If poTab is not the Sheet you want to extract the values from:

var ss = SpreadsheetApp.getActiveSpreadsheet() // Gets the active Spreadsheet into a variable
var poData = ss.getSheetByName("Incoming Sample").getRange('A1:B10').getValues();

Useful resources:

Related