title: Creating a Macro in google spreadsheet to search and then write text
body: <p>What I am trying to accomplish is I would like to search for a term in one cell, if that cell has the term write text to another cell. My specific example would be I would like to search for the term 'DSF' in column 4. If I find 'DSF' it would then write 'w' in column 5 &amp; write '1.2' in column 3. This is searched per row.</p>
  
  <p>I do understand the the .setvalue will write the needed text, but I do not understand how to create a search function. Some help would be greatly appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is the code I am working with at the moment. I am modifying it from something I found.</p>
  
  <pre><code>function Recalls()
  {
   var sh = SpreadsheetApp.getActiveSheet();
   var data = sh.getDataRange().getValues(); // read all data in the sheet
   for(n=0;n&lt;data.length;++n){ // iterate row by row and examine data in column D
     if(data[n][3].toString().match('dsf')=='dsf'){ data[n][4] = 'w'}{ data[n][2] = '1.2'};// if column D contains 'dsf' then set value in index [4](E)[2](C)
   }
   //Logger.log(data)
   //sh.getRange(1,1,data.length,data[3].length).setValues(data); // write back to the sheet
   }
  </code></pre>
  
  <p>With the Logger.log(data) not using the // It works properly but it overwrites the sheet, which will not work since I have formulas placed in a lot of the cells. Also, Maybe I did not realize this but Is there a way to do a live update, as in once I enter text into a cell it will research the sheet? Otherwise having to 'run' the macro with not save me much time in the long run.</p>