title: IF Function - Google Scripts
body: <p>I'm struggling to get my Script to run an IF function. Basically I want to run a script based on specific cell contents.</p>
  
  <p>I would like an IF function to run based on this and have written the following code:</p>
  
  <pre><code>function sendemail () {
  
  
   var ss = SpreadsheetApp.getActiveSpreadsheet(); 
   var s = SpreadsheetApp.getActiveSheet(); 
  
   var targetSheet = ss.getSheetByName("Response");
   var vCodes = ss.getSheetByName("Codes") 
  
   var vResults = targetSheet.getRange("E2").getValues(); 
   var emailAddresses = targetSheet.getRange("B2").getValues() 
  
   var dataRange = vCodes.getRange(1, 1, vResults, 1).getValues();
   var subject = "Here are your Wi-Fi Codes!";
   var vLength = vCodes.getRange("C2").getValues();  
  
   if (vLength == "24 hours"){
   MailApp.sendEmail(emailAddresses, subject, dataRange);
   targetSheet.deleteRows(2);
   vCodes.deleteRows(1,vResults);
      }
  }
  </code></pre>
  
  <p>If the value in C2 is "24 hours" I'd like it to send an e-mail. At the moment when I run the script there are no errors but it doesn't send any e-mail as the IF function obviously isn't running correctly.</p>
  
  <p>If I edit the code to say:</p>
  
  <pre><code> if (vLength == "")
  </code></pre>
  
  <p>then the e-mail sends. It doesn't seem to recognise "24 hours" as valid data to look up.</p>
  
  <ul>
  <li>Can anyone see what I'm doing wrong?</li>
  </ul>