title: How to get Row where two Columns equal specific values
body: <p>I'm very new and I'm trying to create a Time in/Time out sheet.  I have 2 separate sheets, first(ACTIVE) is where the trigger happens that starts the onEdit(e) script.  All the functions that start onEdit(e) affects the second sheet(PASSIVE) to fill out Columns A(Last Name), B(First Name), C(Location), D(Time Out).  I finished making the Time out functions by getting value of A, B, C + Active Row(this isn't the code).  The trigger is always on the same row as the values being copied, so it was relatively simple. On the PASSIVE sheet I have all the values being stored using a code someone made called addRecord where it gets last row + 1 of the PASSIVE sheet and installs the values grabbed from the ACTIVE sheet and plugs them in.  So it adds records without overwriting anything. Works beautifully.  However making a "time in" function has been difficult.  E(Time In) My idea is to getRow of the PASSIVE sheet by searching PASSIVE!A for the Value grabbed from (ACTIVE!A + Active Row) once it finds a match, it sees if (PASSIVE!E + the matched row) is empty.  If it is, it adds new.Date and finishes. If it isn't empty, it ignores this row and continues searching down the line for the next Row that has PASSIVE!A match the grabbed value.  Once it finds this Row, getRow. setValue of (PASSIVE!E + grabbed row, new Date()) </p>
  
  <p>I did find a function online to find the first row that matched the ACTIVE!A with PASSIVE!A.  But it kept overwriting the date on the first match.  It never ignored row with nonempty cell to the next match row.  Maybe I was just slightly off, which is why I'm asking for a lot of detail and explanation in the Answers. 
  This was the Code I used from another answer. </p>
  
  <pre><code>function getCurrentRow() {
    var currentRow = SpreadsheetApp.getActiveSheet().getActiveSelection().getRowIndex();
    return currentRow;
  }
  function onSearch1()
  {
  </code></pre>
  
  <p>What I added</p>
  
  <pre><code>  var row = getCurrentRow();
    var activeLocation = getValue('ACTIVE!A' + row);
  </code></pre>
  
  <p>Continued Other Code</p>
  
  <pre><code> var searchString = activeLocation;
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PASSIVE"); 
      var column =1; //column Index   
      var columnValues = sheet.getRange(2, column, sheet.getLastRow()).getValues(); //1st is header row
    var searchResult = columnValues.findIndex(searchString); //Row Index - 2
  </code></pre>
  
  <p>What I added</p>
  
  <pre><code> setValue(PASSIVE!E + searchResult, new Date().toLocaleString())
  </code></pre>
  
  <p>It worked if everyone has a different name, but the search Result always found the first row of the match, I tried adding an if ACTIVE!A == PASSIVE!A 
   &amp;&amp; PASSIVE!E =="", grabRow (I know this isn't proper code)  But I didn't even know where to put this if function or if it would work or if it would just keep coming up false after it runs the first time true. </p>
  
  <p>Continued Other Code</p>
  
  <pre><code>if(searchResult != -1)
      {
          //searchResult + 2 is row index.
          SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PASSIVE").setActiveRange(sheet.getRange(searchResult + 2, 1))
      }
     if(searchResult = searchResult2) {
      setValue('PASSIVE!E' + searchResult, new Date().toLocaleString())
    }
  }
  Array.prototype.findIndex = function(search){
    if(search == "") return false;
    for (var i=0; i&lt;this.length; i++)
      if(this[i] == search) return i;
  
    return -1;
  }
  </code></pre>
  
  <p>So this is what I used, but not sure if it's the right way to go about this.  Every time I used it, it would only set the SearchResult to the first row it found that had the searchString  I'd actually prefer if it found the last row, considering the add record goes down over time and signing in should be the most recent name.  But I'm guessing if I can just get a function that searches a range and finds the row for two values in specific columns, I can then just <code>setValue('PASSIVE!E' + foundRow, new Date().toLocaleString())</code></p>
  
  <p>Edit 5/9/2019 17:34 PST
  Thank you to those Answering. I'm expanding on the question.</p>
  
  <pre><code>function rowWhereTwoColumnsEqual(value1,col1,value2,col2) {
   var value1=value1 || 'A1';//testing
   var value2=value2 || "";
  </code></pre>
  
  <p>The idea I'm having is to search Column1 of another sheet for, let's say, 'SheetA1' (the first sheet). And Column3 of another sheet for "" (cellisempty).</p>
  
  <pre><code>var value1= 'Sheet1!A1';
   var value2= "";
   var col1='Sheet2!A';
   var col2='Sheet2!C';
   var ss=SpreadsheetApp.getActive();
   var sh=ss.getSheetByName('Sheet2');
   var rg=sh.getDataRange();
   var vA=rg.getValues();
  </code></pre>
  
  <p>However, I don't know how the vA works. I also want to getRow() of the Row that is found in order to use that number in another function.</p>