title: Google App Scripts find text in spreadsheet and return location index
body: <p>I am a novice here to google app scripts and my JavaScript is also not very strong, but neither of these seem to be the problem here as my code works the first time I run it but then when I try to call it again it fails. </p>
  
  <p>Simply I am trying to have a function that will dynamically find a given text in a given range. While it looks like there might be a built in package that does this I cannot figure out how to implement it. And the documentation is not helpful for someone new. </p>
  
  <p>Option 1: was to implement the following: <a href="https://developers.google.com/apps-script/reference/spreadsheet/text-finder#findAll()" rel="nofollow noreferrer">https://developers.google.com/apps-script/reference/spreadsheet/text-finder#findAll()</a> </p>
  
  <p>Since that has not been sucessful in finding out how to do it I moved to creating the following simple two functions, Option 2:</p>
  
  <pre><code>function findIndexRow(range,fText){
    for(var i = 0; i&lt;range.length;i++){
      for(var j = 0; j&lt;range.length;j++){
        if(range[i][j] == fText){
          var fTextRow = i+1;
          var fTextCol = j+1;
        }
      }  
    }
    return fTextRow
  }
  
  function findIndexCol(range,fText){
    for(var i = 0; i&lt;range.length;i++){
      for(var j = 0; j&lt;range.length;j++){
        if(range[i][j] == fText){
          var fTextRow = i+1;
          var fTextCol = j+1;
        }
      }  
    }
    return fTextCol
  }
  </code></pre>
  
  <p>It takes in a range that I defined like:</p>
  
  <pre><code>var sheet = SpreadsheetApp.openById('the-gsheet-id');
  var CurrSheet = sheet.getSheetByName('Sheet1');
  var SHTvalues = CurrSheet.getDataRange().getValues();
  </code></pre>
  
  <p>So the above works when I call it once in my main code but the second time it returns <code>null</code>, help here as to why re calling the same function does not work. </p>
  
  <pre><code>var text1Row = findIndexRow(SHTvalues,"text1");
  var text1Col = findIndexCol(SHTvalues,"text1");
  Logger.log(text1Row)
  Logger.log(text1Col)
  var text2Row = findIndexRow(SHTvalues,"text2");
  var text2Col = findIndexCol(SHTvalues,"text2");
  Logger.log(text2Col)
  Logger.log(text2Row)
  </code></pre>
  
  <p>I can't understand why my logs return the correct values for <code>text1Row</code> and <code>text1Col</code> but when it is called a second time the <code>text2Row</code> and <code>text2Col</code> both return <code>null</code></p>