Use the following code to accomplish your goal.
Code
function onOpen() {
SpreadsheetApp.getUi().createMenu('Custom Format')
.addItem('Max & Color', 'getmaxColor').addToUi();
}
function getmaxColor() {
var ss = SpreadsheetApp.getActive(), aRange = ss.getActiveRange();
var data = aRange.getValues(), colors = aRange.getBackgrounds();
var dest = aRange.offset(0, data[0].length, 1, 1);
var index = getmaxIndices(data);
var max = data[index.i][index.j], color = colors[index.i][index.j];
dest.setValue(max).setBackground(color);
}
function onEdit() {
var ss = SpreadsheetApp.getActive(), col = ss.getActiveCell().getColumn();
if(col < 7) {
var aRange = ss.getRange("A1:F7"), data = aRange.getValues();
var colors = aRange.getBackgrounds();
var dest = aRange.offset(0, data[0].length, 1, 1)
var index = getmaxIndices(data);
var max = data[index.i][index.j], color = colors[index.i][index.j];
dest.setValue(max).setBackground(color);
}
}
function getmaxIndices(data) {
var max = 0, indexI = 0, indexJ = 0;
for(var i=0, iLen=data.length; i<iLen; i++) {
for(var j=0, jLen=data[0].length; j<jLen; j++) {
if(data[i][j] > max) {
max = data[i][j], indexI = i, indexJ = j;
}
}
}
return {"i":indexI, "j":indexJ};
}
Explained
The onOpen() adds a menu item. Select the range you want to evaluate and select the menu option Max & Color. The values and backgrounds are collected as is an offset range. Then the indices (2d-array) of the max value are obtained, through the getmaxIndices(). Afterwards the corresponding max value and color is set.
The onEdit() does almost the same, but it has a fixed range. It will only fire if a cell is edited and if the edited cell belongs to the A1:F7
range.
Note
The reason for getting the error message, can be read in this answer: custom function
Example
I've added the sample code into your example file.
The only way I know is to use a 'dummy' parameter to the function, that is not really used in the custom function, but will trigger the function to recalculate.
So, where you would normally use:
=sumWhereBackgroundColorIs(color, rangeSpecification)
you would now use
sumWhereBackgroundColorIs(color, rangeSpecification, F1)
In F1 (or any other cell you may want to use) you can have value (e.g. 1) that when changed (e.g: incremented with 1) will force the recalculation of the custom function. This 'incrementing act' can also be scripted.
Best Answer
Try Class TextStyleBuilder from Google Apps Script.
Reference