I am looking to format cells with a border if the title cells both contain text. To trial I have used number 1 for the search key. I think it may be in the range I am supplying for the .setBorder.

Final Product would look like the attached image. Final Product

function onEdit(){

  var sheetName = 'Sheet1'; //Customizable

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var sheet = ss.getSheetByName(sheetName);

  var rangeAll = sheet.getRange(1,1,20,20);

  var cellColumnStart = 1;

  var cellRowStart = 1;

  var numRows = rangeAll.getNumRows();

  var numColumns = rangeAll.getNumColumns();

  var testValues = rangeAll.getValues();

 rangeAll.setBorder(false, false, false, false, null, null, "black", SpreadsheetApp.BorderStyle.SOLID); //remove existing borders 

  for  (var i=1; i < numRows-1; i++){

    for (var j=1; j < numColumns-1; j++){

      if (testValues[1][j] == '1' && testValues [i][1] == '1') {

        var rangeCell = sheet.getRange(i,j);

        rangeCell.setBorder(true, true, true, true, null, null, "black", SpreadsheetApp.BorderStyle.SOLID); //box borders 




  • sorted. changed var i = 0, var j=0, test values to 0 not 1 and range to i+1 and j+1. Still working on the test value to check if cell contains anything not just 1. – Woody Jan 31 at 6:54

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.