Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9699

Depending on Sheet being edited, get a cell value and trigger OnEdit update

$
0
0

This code works but not as intended. The workbook has several tabs (Sheets) and if the user is editing Tab1, then and only then a trigger OnEdit should execute. If the user is editing some other tab (ie. Tab2 or anything other than Tab1) then code should exit.

The purpose is to look up the last value in Column G (date value as mm/dd/yy) and Column I (number) and store them into cell F2

How may I test if user is editing sheet named Tab1 and stop code if on some other tab ?

function GetLastValueInColumnG() {  var ss = SpreadsheetApp.getActiveSpreadsheet(); //Get the active Spreadsheet.  var sheet=ss.getSheetByName("Tab1");          //Code should run only on Tab1 sheet.  sheet.activate() ;                           //hardcoded but dont want this.  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();    var lastRow = 2;  var lastColumn = 1;  var Gvals = sheet.getRange("G1:G").getValues();  var Glast = Gvals.filter(String).length;  var lastCell = sheet.getRange(Glast +1, lastColumn);  var row = Glast;  var col = 9;  var data = sheet.getRange(row, col).getValue();  var dtdata = sheet.getRange(row, col-2).getValue();  var formatteddtdata = Utilities.formatDate(new Date(dtdata), "GMT+1", "MM/dd/YY");  var row = 1;  var col = 6;  // stored in Column F Row 1  sheet.getRange(row, col).setValue('Stored (last: '+ formatteddtdata +' $ '+ data +')');}

Viewing all articles
Browse latest Browse all 9699

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>