1
votes

How do I search a column for a word, and then get the location of the cell that contains that word?

Example: if the word I want to search was found in cell A6, I want to get A6.

My code below is able to find the word "xyz", but I don't know how to record its cell location in a variable.

function search() {

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  for(var i=1;i<sheet.getLastRow();i++){
    var value = sheet.getRange(i, 1).getValue();

    if(value == 'xyz'){
          //how do I get the cell location of xyz?
          var cell = ???
    }
  }

}

Thank you.

1
get the current cell that you are currently iterating over - Josan Iracheta

1 Answers

0
votes

The location of the cell would be the value of i and the column value when the conditional statement is true.

if(value == 'xyz'){
  //i is the row
  //1 is the column
  var cell = sheet.getCell(i,1);
}