Suppose I want to color scale complete rows on the basis of values in a column (using Google Sheets inbuilt color scale option in the conditional formatting menu). How do I achieve this?
Color Scale entire row based on one column
Welcome. Please add a brief description of your search/research efforts as is suggested in How to Ask. –
Karachi
try:
function onOpen() {
// adds a custom menu to run the function manually
SpreadsheetApp.getUi().createMenu('Extend Colorscale')
.addItem('Apply', 'applyBackgroundColors')
.addToUi();
applyBackgroundColors(startfromrow, paintadditionalcolumns, paintwholerow);
}
var sheetname = 'Sheet2'; // change sheet name
var readcolorfromcolumn = 4; // column 4 = column D
var startfromrow = 2; // run script from this row
var paintadditionalcolumns = 0; // 2 = paint also E:F
var paintwholerow = false; // true or false
function onEdit(e) {
if (e.range.getSheet().getName() === sheetname && e.range.getColumn() === readcolorfromcolumn) {
applyBackgroundColors(startfromrow, paintadditionalcolumns, paintwholerow);
}
}
function applyBackgroundColors(startRow, extraColumns = paintadditionalcolumns, fullRow = paintwholerow) {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetname);
if (!sheet) return;
const lastRow = sheet.getLastRow();
const start = startRow;
const lastColumn = fullRow ? sheet.getMaxColumns() : readcolorfromcolumn + extraColumns;
for (let rowIndex = start; rowIndex <= lastRow; rowIndex++) {
const cell = sheet.getRange(rowIndex, readcolorfromcolumn);
const bgColor = cell.getBackground();
sheet.getRange(rowIndex, 1, 1, lastColumn).setBackground(bgColor);
}
}
How to fix this, is to sect the entire row and if there is a section you don't want to color then don't include it in the range data. Full row: 4:4
off section: D4:Z4
If you are asking how to input the column values then use the formula Vlookup("Range that it is based on","the ratio","2",if it is text then"false")
The ratio means the if statements like If A9 equals 7 then 9
in that case it would equal 9 or you could just color it.
here is a sheet for you to see it laid out Here
The example sheet is in the trash, not very effective for an answer here. If I understand what the OP is asking (I went looking for this question because I have it as well) this does not answer the question, it makes the rows uncolored. The goal is to color scale based on a column (ie data in columns a-c doesn't skew what is considered the "range" of the scale but they are formatted based on the where column d is in the range) –
Femoral
© 2022 - 2025 — McMap. All rights reserved.