0
votes

I'm trying to fetch the data out of a cell in a range, but i get an error saying the cell i'm trying to read is out of range

after opening the document the code goes

  var range = sheet.getRange("A1:B7");

  var cell = range.getCell(2, 3);
  var cellValue = cell.getValue();
  Logger.log(cell);

and my sheet looks like this:

screenshot of my sheet

What is the error here?

1

1 Answers

0
votes

Please, note that the getCell() method accepts arguments as follows: row, column (with 1-based Integer values). In case the Range it is called upon is in at least one dimension smaller than than the dimension size of the getCell() call, it throws an error.

Your Range dimensions are: row = 7, column = 2.

Your getCell() call dimensions are: row = 2, column = 3.

Thus, the cell referenced in the offset from the Range by 1 column.

Useful links

  1. getCell() method reference.