RemcoE33

u/GGeorgeouss - VBA to script

Jul 15th, 2021 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function priceAlert(){
  2.   const ss = SpreadsheetApp.getActiveSpreadsheet();
  3.   const summary = ss.getSheetByName('Summary');
  4.   const email = summary.getRange('P3').getValue();
  5.   const columnAValues = summary.getRange(5, 1, summary.getLastRow()).getValues().flat();
  6.   const values = summary.getRange(5, 26, summary.getLastRow(), 3).getValues();
  7.  
  8.   for(i = 0; i < values.length; i++){
  9.     const row = values[i];
  10.     if(row[2] == true){
  11.       console.log(`Found true value: ${columnAValues[0]} | ${row[0]} | ${row[1]}`);
  12.       summary.getRange(5 + i, 16).clearContent();
  13.       sendMail(email, columnAValues[i], row[0], row[1]);
  14.     }
  15.   }
  16.  
  17. }
  18.  
  19. function sendMail(email, a, z, aa){
  20.   const subject = `${a} has reached your ${aa} target at ${z}`;
  21.   GmailApp.sendEmail(email, subject, '');
  22.   console.log(`## Send email: ${a} | ${z} | ${aa} ##`);
  23. }
Add Comment
Please, Sign In to add comment