0

I need to set borders to a range in row if first cell in this row is not empty.

I have this code

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();
  var sheetmon = ss.getSheetByName('Monitor'); 
  var rows = sheetmon.getRange('G59:P90'); 
  var numRows = rows.getNumRows(); 
  var values = rows.getValues(); 
  var testvalues = sheetmon.getRange('G59:G90').getValues(); 

  rows.setBorder(false, false, false, false, false, false, "red", SpreadsheetApp.BorderStyle.SOLID_MEDIUM); 

  for (var i = 0; i <= numRows - 1; i++) {
      var n = i + 1;
      if (testvalues[i] > 0) { 
        sheetmon.getRange('a' + n + ':g' + n).setBorder(true, true, true, true, true, true, "red", SpreadsheetApp.BorderStyle.SOLID_MEDIUM); 
      }
  }
}

But it works only for the first row in range G59:G90

Where I am wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.