I want,
If Sheet1 ColumnB = Sheet89 ColumnA
Then matched Sheet1 Column B cells will be green Here is my demo sheet.
Based on some guideline I made this but not working.
function formatting() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var columnB = sheet.getRange(1, 2, sheet.getLastRow()-1, 1);
var bValues = columnB.getValues();
var sheet89 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet89');
var columnO = sheet89.getRange(1, 1, sheet.getLastRow()-1, 1);
var oValues = columnO.getValues();
for (var h = 0; h < bValues.length; h++) {
for (var i = 0; i < oValues.length; i++) {
if (oValues[i][0] == bValues[h][0]) {
sheet.getRange(i + 2, 1, 1, 1).setBackgroundColor('green');
}
}
}
}
What I understand to be required (and not what the example sheet shows at present) is possible with Conditional formatting.
In Google Spreadsheets conditional formatting across sheets is not nearly as straightforward as within a single sheet, because of security and therefore authorisation. You may, for speed for example, prefer to copy the content of
Sheet89
intoSheet1
(just two cells) to avoid that issue, or indeed write a script instead. At least keep the ranges as small as practical.However it is possible, though may be slow and require authorisation.
Please clear any conditional formatting from
Sheet1 ColumnA
then:Select ColumnA in
Sheet1
, Format, Conditional formatting..., Format cells if...Custom formula is
andwith highlighting of your choice and Done.
k e y
above represents the unique identification code forSheet89
(will look something like1u4vq8vDne-aKMVdJQPREGOxx7n99FqIb_kuJ_bG-PzM
).The image shows at present what is in ColumnC of the image (but is in ColumnA of the example) and F1 and F2 in the image show what is in ColumnA of
Sheet89
of the example. The paler brown has been applied with Conditional formatting::