The code is as follow:
function find(sheet,searchKey) {
  var data = sheet.getDataRange().getValues();
  for( var i in data )
    for( var j in data[i] )
      if( searchKey == data[i][j] )
        return sheet.getRange(parseInt(i)+1,parseInt(j)+1);
  return null;
}
To use the code, you can just call it as follow:
function usageExample() {
  //replace 1st occurence of "foo" with "bar"
  var range = find(SpreadsheetApp.getActiveSheet(),"foo");
  if( range != null )
    range.setValue("bar");
}
 
 
2 comments:
thanks
You are welcome.
Post a Comment