Excel apparently has this type of conditional formatting built-in.
I'd like to accomplish the same in Google Sheets via Google Apps Script. The following should demonstrate the before and after conditions:
Example Dataset
A B C
1 apple Macintosh
2 apple Granny Smith
3 orange Florida
4 orange Valencia
5 pear Garden
6 banana Chiquita
Resulting Example Dataset
A B C
1 apple Macintosh
2 apple Granny Smith
---------------------------
3 orange Florida
4 orange Valencia
---------------------------
5 pear Garden
---------------------------
6 banana Chiquita
---------------------------
The script/answer to this question should display a bottom border under the entire row (of columns 'A', 'B' & 'C') for rows: 2, 4, 5, & 6. The spreadsheet logic is fairly straightforward:
- In cell
C1
,=IF(A1=A2,"NOBORDER","BORDER")
- Then wrap the above in
=IF(C1="BORDER", addBorder(A1:C1), "NOBORDER")
In a larger dataset, this formating will help the end user see logical groupings more easily. A Google Apps Script is required because the data will be updating dynamically.
Below is some sample Google Apps Script code, but it's not working
function onEdit(event) {
var sheet = SpreadsheetApp.getActiveSheet();
var range = event.range;
var startingRow = range.getRow();
var numRows = range.getNumRows();
for (var i = 1; i <= numRows; i++) {
var rowNbr = startingRow + i - 1;
Logger.log("changed row %s",rowNbr );
//Now check the WHOLE row
var colLeft=1; //1=A
var colRight=11; //11=K
var row = sheet.getRange(rowNbr,colLeft, 1, colRight - colLeft + 1);
if(row.isBlank()) {
row.setBorder(false, null, true, null, null, null, "red", SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
} else {
row.setBorder(false, null, null, null, null, null, "black", SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
}
}
}