How do I run through rows and fetch the value of a cell, if another cell is true?

In Google Sheets, I have X rows with data in 10 columns. The first row contain headers.

I need to run through every row in my current sheet, check column B, in the current row, and if the value of that cell is “FOUND”, then I want to fetch the value of the cell in column C, in the current row.

I have this experimental code, but it doesn’t work properly, as it returns all incidences regardless of values:

function curCellValue() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  for (var i = 1; i < data.length; i++) {
    if (data[i][1] = 'FOUND'){


You have a typo: the line below always returns true, because it is assigning:

    if (data[i][1] = 'FOUND'){

Change the assignment to a check ===. Then you’ll find rows that are FOUND.

Leave a Reply

Your email address will not be published. Required fields are marked *