Cannot find method getRange(number,number)?

Issue:

  • getRange is a method that’s available both on Spreadsheet class and Sheet class.

  • However, only getRange(string) is available on Spreadsheet(ss). So, you can use ss.getRange('Sheet1!A1:B4').

  • And getRange(number,number) is only available on sheet. So, You can use ss.getActiveSheet().getRange(1,4).

  • Sheet class also accepts other variations of this method, but Spreadsheet class doesn’t, which only accepts string as the only parameter.

  • Sometimes, You also receive

    Exception: The parameters (String,number,number,number) don’t match the method signature for SpreadsheetApp.Spreadsheet.getRange

    The reason the first parameter is a string is because there is a attempt by JavaScript engine to match the actual function call signature: getRange(string). It converts the first number to string, but it doesn’t know what to do with the rest of the parameters(numbers). As there is no method signature that match the call (string, number,number,number) on Spreadsheet class, it throws a error.

Solution:

Use proper methods on the intended class as described in the official documentation. For most purposes, You must use the Sheet class.

SpreadsheetApp.getActive().getSheets()[0].getRange(1,1)

Leave a Comment