-1

everyone!

I'm trying to write a script where the cell G3 on the sheet 'ref view' will change to 'Yes' if the cell D9 on 'view' contains 'BP' when I run it. The problem is that the execution is completed without errors but when I try to test it nothing happens.

This is the code:


  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var sheetInfo = ss.getSheetByName('ref view')
  var data = sheet.getDataRange().getValues();
  var rangeView = ss.getRange('View!D9');
  var cell = ss.getRange('ref view!G3');
  var range = rangeView;
  for(var i=0; i<data.length; i++) {

    if(rangeView == 'BP') {
      sheet.getRange(cell).clear().setValue('Yes');
    }
  }
} ```
  • Read and test [this](https://stackoverflow.com/questions/63720612/what-does-the-range-method-getvalues-return-and-setvalues-accept) – TheMaster Oct 23 '22 at 19:54

1 Answers1

0

Try it this way:

function one() {
  var ss = SpreadsheetApp.getActive();
  var sh1 = ss.getActiveSheet();
  var vs1 = sh1.getDataRange().getValues();
  var sh2 = ss.getSheetByName('ref view')
  var sh3 = ss.getSheetByName('view');
  var sh3D9v = sh3.getRange('D9').getValue();//value
  var sh2G3r = sh2.getRange('G3');//Range
  for(var i=0; i<vs1.length; i++) {
    if(sh3D9v == 'BP') {
      sh1.getRange(sh2G3r).setValue('Yes');
    }
  }
}

Be aware that a range does not return a value without the use of a getValue() or a getValues();

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • Hi, Cooper! Thanks for replying. When I try your suggestion, I get this error: Exception: Range not found one @ Code.gs:11 – kore155 Oct 23 '22 at 21:04