Search code examples
google-apps-scriptgoogle-sheetsgoogle-sheets-macros

I need stop a macro according to the value of a cell


I need this macro to stop its execution in the gap that I leave if the value of E21 is different from 1

how can I do this?

function _1() {
  var spreadsheet = SpreadsheetApp.getActive();
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  spreadsheet.getRange('E9').activate();
  spreadsheet.getCurrentCell().setFormula('E23');
  SpreadsheetApp.flush();
  spreadsheet.getRange('E9').activate();
  spreadsheet.getRange('E9').copyTo(spreadsheet.getActiveRange(), 
SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);


   (I NEED STOP HERE IF E21<>1)



  spreadsheet.getRange('E17').activate();

 spreadsheet.setActiveSheet(spreadsheet.getSheetByName('REGISTROS'), true);
      spreadsheet.getRange('2:2').activate();

Solution

  • I don't know what sheet E21 is on but you can do this

    if(sheet.getRange('E21').getValue()!=1) return;