I could not believe that this wasn't a thing that already exists. Or if it is I'm not good enough at googling it.
Right now what this does out of the box is, in 'Sheet1', based on the values in column A, put a border (across columns A:M) between rows where column A values diverge.
What it's been useful for is: Differentiating rows of the spreadsheet based on date. Essentially, putting a line in between every date chunk. Automatically. Like this. You can change the range and so on to actually do that for anything though.
function onOpen() {
GroupDataByRows(); // trigger this function on sheet opening
}
function GroupDataByRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1'); // apply to sheet name only
var rows = sheet.getRange('a1:m'); // range to apply formatting to
var numRows = rows.getNumRows(); // no. of rows in the range named above
Logger.log("Updating sheet " + sheet.getName() + " between different column A values");
var data = sheet.getRange('a1:a').getValues().filter(String); // array of the values in question
rows.setBorder(false, false, false, false, false, false);
// rows.setBorder(true, true, true, true, true, true, "black", SpreadsheetApp.BorderStyle.SOLID); // reset existing borders before applying rule
for (var i = 0; i <= numRows - 1; i++) { // going through column A, check if they are equal to the previous row
var n = i + 1;
if (data[i] == []) { // If you've hit the end (empty), cease
return;
}
if ((data[i]+"") !== (data[i-1]+"")) {
// add a border line if the values have now changed
sheet.getRange('a' + n + ':m' + n).setBorder(true, false, false, false, false, false, "black", SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
}
}
};