function setborders() {
var menu = [{name: "Borders for nonempty cells", functionName: "borders"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu("Set Borders", menu);
}
function borders() {
var ss = SpreadsheetApp.getActive();
var numsheets = ss.getNumSheets();
var allsheets = ss.getSheets();
for (var s in allsheets){
var sheet=allsheets[s]
var range = sheet.getRange("A2:V1000");
var values = range.getValues();
var offsetRow = range.getRowIndex();
for(var i = 0; i < allsheets.length; i++)
if(['Current Sales','Pending Orders','Subcontract Orders','Partial Shipped','Quotes','Archived Sales'].indexOf(allsheets[i].getName())){
if(sheet.getRange(range.getRow(), 1).getValue()) {
range.setBorder(false, false, false, false, false, false);
SpreadsheetApp.flush();
for (var i = 0; i < values.length; i++) {
if (values[i][0]) { // Only for non-empty A column cells
sheet.getRange("A" + (i + offsetRow) + ":V" + (i + offsetRow)).setBorder(true, true, true, true, false, false, "black",SpreadsheetApp.BorderStyle.SOLID);
}
}
for (i = 0; i < values.length; i++) {
if (values[i][0] && values[i][14]) {
sheet.getRange("O" + (i + offsetRow) + ":O" + (i + offsetRow)).setBorder(true, true, true, true, true, true, "black",SpreadsheetApp.BorderStyle.SOLID_THICK);
}
}
for (i = 0; i < values.length; i++) {
if (values[i][0] && values[i][18]) {
sheet.getRange("S" + (i + offsetRow) + ":S" + (i + offsetRow)).setBorder(true, true, true, true, true, true, "black",SpreadsheetApp.BorderStyle.SOLID_THICK);
}
}
for (i = 0; i < values.length; i++) {
if (values[i][0] && values[i][19]) {
sheet.getRange("T" + (i + offsetRow) + ":T" + (i + offsetRow)).setBorder(true, true, true, true, true, true, "black",SpreadsheetApp.BorderStyle.SOLID_THICK);
}
}
for (i = 0; i < values.length; i++) {
if (values[i][0] && values[i][20]) {
sheet.getRange("U" + (i + offsetRow) + ":U" + (i + offsetRow)).setBorder(true, true, true, true, true, true, "black",SpreadsheetApp.BorderStyle.SOLID_THICK);
}
}
for (i = 0; i < values.length; i++) {
if (values[i][0] && values[i][21]) {
sheet.getRange("V" + (i + offsetRow) + ":V" + (i + offsetRow)).setBorder(true, true, true, true, true, true, "black",SpreadsheetApp.BorderStyle.SOLID_THICK);
}
}
}
}
}
}