Nicholas Besse
Nicholas Besse

Reputation: 3

Unable to retrieve single value from array of values

I'm trying to retrieve a value to do a String comparison test and I can't seem to retrieve the single value from an array of values. Here's my code:

function CoverageCalculator() {
  var sheet = SpreadsheetApp.getActiveSheet();

  var searchRange = sheet.getRange('D3:D20')
  var rangeValues = searchRange.getValues();

  var Test = searchRange[1][1];
}

In debug mode, "Test" is undefined, any ideas on why this might be the case?

Upvotes: 0

Views: 39

Answers (1)

Wicket
Wicket

Reputation: 38425

Change

var Test = searchRange[1][1];

to

var Test = rangeValues[1][0];

The above because searchRange is a Range object, not an array, but rangeValues it's. Regarding the indexes, the first one determines the row, and the second the column and considering that the source range is D3:D20 the resulting array has 17 rows high and 1 column width, then the maximum valid index for the second index is 0.

Upvotes: 1

Related Questions