如果同一列中的值重复,我正在寻找谷歌电子表格突出显示单元格的公式
谁能帮我查询这个问题?
尝试这个:
Custom formula is
=countif(A:A,A1)>1
或更改A
为您选择的列)A1:A100
)。将检查 A1:A100 单元格中写入的任何内容,如果有重复(出现不止一次),则将其着色。
对于使用逗号 ( ,
) 作为小数分隔符的语言环境,参数分隔符很可能是分号 ( ;
)。也就是说,请尝试:=countif(A:A;A1)>1
,而不是。
对于多列,使用countifs
.
虽然zolley 的回答非常适合这个问题,但这里有一个适用于任何范围的更通用的解决方案,以及解释:
=COUNTIF($A$1:$C$50, INDIRECT(ADDRESS(ROW(), COLUMN(), 4))) > 1
请注意,在此示例中,我将使用 range A1:C50
。第一个参数 ( $A$1:$C$50
) 应替换为您要突出显示重复项的范围!
突出显示重复项:
Format
>Conditional formatting...
Apply to range
,选择应应用规则的范围。Format cells if
中,在下拉列表中选择Custom formula is
。为什么它有效?
COUNTIF(range, criterion)
, 会将每个单元格与range
中的每个单元格进行比较criterion
,其处理方式与公式类似。如果没有提供特殊运算符,它将范围内的每个单元格与给定单元格进行比较,并返回找到的与规则匹配的单元格数(在本例中为比较)。我们使用固定范围(带$
符号),以便我们始终查看完整范围。
第二个块,INDIRECT(ADDRESS(ROW(), COLUMN(), 4))
将返回当前单元格的内容。如果将其放置在单元格内,文档会为循环依赖而哭泣,但在这种情况下,公式会像在单元格中一样被评估,而不会更改它。
ROW()
并将分别COLUMN()
返回给定单元格的行号和列号。如果未提供参数,则将返回当前单元格(这是从 1 开始的,例如,B3
将返回 3ROW()
和 2 COLUMN()
)。
然后我们使用:ADDRESS(row, column, [absolute_relative_mode])
将数字行和列转换为单元格引用(例如B3
。请记住,当我们在单元格的上下文中时,我们不知道它的地址或内容,我们需要内容才能进行比较)。第三个参数负责格式,并4
返回格式INDIRECT()
喜欢。
INDIRECT()
, 将获取单元格引用并返回其内容。在这种情况下,当前单元格的内容。然后回到开始,COUNTIF()
将测试范围内的每个单元格与我们的单元格,并返回计数。
最后一步是让我们的公式返回一个布尔值,方法是使其成为一个逻辑表达式:COUNTIF(...) > 1
。使用> 1
是因为我们知道至少有一个细胞与我们的细胞相同。那是我们的单元格,它在范围内,因此将与自身进行比较。因此,为了表示重复,我们需要找到 2 个或更多与我们匹配的单元格。
资料来源:
从“文本包含”下拉菜单中选择“自定义公式为:”,然后写入:“=countif(A:A, A1) > 1”(不带引号)
我完全按照zolley 的建议做了,但应该做一些小的更正:使用"Custom formula is"而不是"Text Contains"。然后条件渲染将起作用。
=COUNTIF(C:C, C1) > 1
Explanation: The C1
here doesn't refer to the first row in C. Because this formula is evaluated by a conditional format rule, instead, when the formula is checked to see if it applies, the C1
effectively refers to whichever row is currently being evaluated to see if the highlight should be applied. (So it's more like INDIRECT(C &ROW())
, if that means anything to you!). Essentially, when evaluating a conditional format formula, anything which refers to row 1 is evaluated against the row that the formula is being run against. (And yes, if you use C2 then you asking the rule to check the status of the row immediately below the one currently being evaluated.)
So this says, count up occurences of whatever is in C1
(the current cell being evaluated) that are in the whole of column C
and if there is more than 1 of them (i.e. the value has duplicates) then: apply the highlight (because the formula, overall, evaluates to TRUE
).
=AND(COUNTIF(C:C, C1) > 1, COUNTIF(C$1:C1, C1) = 1)
Explanation: This only highlights if both of the COUNTIF
s are TRUE
(they appear inside an AND()
).
The first term to be evaluated (the COUNTIF(C:C, C1) > 1
) is the exact same as in the first example; it's TRUE
only if whatever is in C1
has a duplicate. (Remember that C1
effectively refers to the current row being checked to see if it should be highlighted).
The second term (COUNTIF(C$1:C1, C1) = 1
) looks similar but it has three crucial differences:
It doesn't search the whole of column C
(like the first one does: C:C
) but instead it starts the search from the first row: C$1
(the $
forces it to look literally at row 1
, not at whichever row is being evaluated).
And then it stops the search at the current row being evaluated C1
.
Finally it says = 1
.
So, it will only be TRUE
if there are no duplicates above the row currently being evaluated (meaning it must be the first of the duplicates).
Combined with that first term (which will only be TRUE
if this row has duplicates) this means only the first occurrence will be highlighted.
=AND(COUNTIF(C:C, C1) > 1, NOT(COUNTIF(C$1:C1, C1) = 1), COUNTIF(C1:C, C1) >= 1)
Explanation: The first expression is the same as always (TRUE
if the currently evaluated row is a duplicate at all).
The second term is exactly the same as the last one except it's negated: It has a NOT()
around it. So it ignores the first occurence.
Finally the third term picks up duplicates 2, 3 etc. COUNTIF(C1:C, C1) >= 1
starts the search range at the currently evaluated row (the C1
in the C1:C
). Then it only evaluates to TRUE
(apply highlight) if there is one or more duplicates below this one (and including this one): >= 1
(it must be >=
not just >
otherwise the last duplicate is ignored).
我尝试了所有选项,但都没有奏效。
只有谷歌应用脚本帮助了我。
来源:https ://ctrlq.org/code/19649-find-duplicate-rows-in-google-sheets
在文档顶部
1.- 转到工具 > 脚本编辑器
2.-设置脚本的名称
3.-粘贴此代码:
function findDuplicates() {
// List the columns you want to check by number (A = 1)
var CHECK_COLUMNS = [1];
// Get the active sheet and info about it
var sourceSheet = SpreadsheetApp.getActiveSheet();
var numRows = sourceSheet.getLastRow();
var numCols = sourceSheet.getLastColumn();
// Create the temporary working sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var newSheet = ss.insertSheet("FindDupes");
// Copy the desired rows to the FindDupes sheet
for (var i = 0; i < CHECK_COLUMNS.length; i++) {
var sourceRange = sourceSheet.getRange(1,CHECK_COLUMNS[i],numRows);
var nextCol = newSheet.getLastColumn() + 1;
sourceRange.copyTo(newSheet.getRange(1,nextCol,numRows));
}
// Find duplicates in the FindDupes sheet and color them in the main sheet
var dupes = false;
var data = newSheet.getDataRange().getValues();
for (i = 1; i < data.length - 1; i++) {
for (j = i+1; j < data.length; j++) {
if (data[i].join() == data[j].join()) {
dupes = true;
sourceSheet.getRange(i+1,1,1,numCols).setBackground("red");
sourceSheet.getRange(j+1,1,1,numCols).setBackground("red");
}
}
}
// Remove the FindDupes temporary sheet
ss.deleteSheet(newSheet);
// Alert the user with the results
if (dupes) {
Browser.msgBox("Possible duplicate(s) found and colored red.");
} else {
Browser.msgBox("No duplicates found.");
}
};
4.-保存并运行
在不到 3 秒的时间里,我的重复行被着色了。只需复制脚本即可。
如果您不了解 google apps scripts ,此链接可能会对您有所帮助:
https://zapier.com/learn/google-sheets/google-apps-script-tutorial/
https://developers.google.com/apps-script/overview
我希望这有帮助。