I see some people have had similar issues in the past, but they seems to be just different enough for the solution to be different. So here goes:
I'm trying to return a range of known size in Google Apps Scripts for sheets like so:
var myRange = ss.getRange(2,1,14,4);
However, I'm getting an error like this:
Cannot find method getRange(number,number,number,number).
Note that using a1notation, as shown below, works just fine:
var myRange = ss.getRange("A2:D15");
The getRange
function has several permutations
I've tried using all the different permutations (using hard-coded numbers), and only the a1notation one works. Any thoughts?
As mentioned in my comment, I'd be interested to see how you've built the ss
var in your code.
It could be you're pointing to a spreadsheet, and not a sheet within that spreadsheet.
I've put together a simple example of the getRange. This works and it logs how many columns and rows in the range to the Logger.
As you can see, the ss
var is used for the spreadsheet and the sheet
var for the sheet within the spreadsheet itself.
function getSomeRange(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var myRange = sheet.getRange(2,1,14,4);
Logger.log("Number of rows in range is "+myRange.getNumRows()+ " Number of columns in range is "+ myRange.getNumColumns());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With