如果值与另一个工作表中的单元格匹配,我想突出显示一个单元格。
建议的解决方案
FOR EACH row in 'sheet1'
IF column C == TRUE
&& column D (value split by comma, only search values with 'tf' in) does not match any cell in 'sheet2'
Highlight the cell Red
示例值
手机D9
“平台,TF平台,TF用户”
示例表
https://docs.google.com/spreadsheets/d/1eI9FTVNuyMEzQTJnHzufz_gElE53AMmk-mxVEWKPdRk/edit?usp=sharing
答案 0 :(得分:0)
您可以使用MATCH
功能搜索其他工作表。
例如:=NOT(ISERROR(MATCH(D1,'SheetName'!C:C,0)))
在D1
列[SheetName]
中搜索C
单元格值
答案 1 :(得分:0)
您可以在Apps脚本中执行以下操作:
sheet1
(C,D列)中检索值。对于每一行,请执行以下操作:TF
的数组。 String.prototype.split()和Array.prototype.filter()用于此目的。sheet2
(E列)中的值检索数组。sheet2
中的值)相匹配。可能与以下几行有关:
function highlightCells() {
var ss = SpreadsheetApp.getActive();
var sheet1 = ss.getSheetByName("sheet1");
var sheet2 = ss.getSheetByName("sheet2");
// Get the values from sheet1 (column C, D):
var firstRow = 1;
var firstCol = 3;
var numRows = sheet1.getLastRow() - firstRow + 1;
var numCols = 2;
var originValues = sheet1.getRange(firstRow, firstCol, numRows, numCols).getValues();
// Iterate through each row in sheet1:
originValues.forEach(function(row, i) {
var checkbox = row[0];
if (checkbox === true) { // Check that checkbox in column C is checked
var cellValue = row[1];
// Get the comma-separated values in column D (only if the contain `TF`, capitalized):
var values = cellValue.split(",").filter(function(value) {
return value.indexOf("TF") !== -1;
});
// Get the values from sheet2:
var firstRow2 = 1;
var column = 5;
var numRows2 = sheet2.getLastRow() - firstRow2 + 1;
var valuesSheet2 = sheet2.getRange(firstRow2, column, numRows2).getValues().map(function(value) {
return value[0];
});
// Look for any comma-separated value in column D (sheet1) that matches a value in column E (sheet2):
var found = values.some(function(value) {
return valuesSheet2.indexOf(value) > -1;
});
// If any value matches, change background color in to red:
if (found) {
sheet1.getRange(i + firstRow, 4).setBackground("red");
}
}
});
}
我不确定如果值匹配或是否不匹配(您的问题不清楚)是否要设置背景色。如果值匹配,则会更改背景颜色。如果您希望它不匹配时进行更改,则应改为if (!found) {
。