我正在寻找谷歌电子表格公式 如果值在同一列中重复,则突出显示单元格

请问有人能帮我解答这个问题吗?


当前回答

我试了所有的方法,没有一个奏效。

只有谷歌应用程序脚本帮助我。

来源: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秒的时间里,我的重复行被着色了。只需要复制脚本。

如果你不知道谷歌应用程序脚本,这个链接可以帮助你:

https://zapier.com/learn/google-sheets/google-apps-script-tutorial/

https://developers.google.com/apps-script/overview

我希望这能有所帮助。

其他回答

试试这个:

选择整个列 点击格式 单击“条件格式” 单击“添加另一个规则”(或编辑现有/默认的规则) “格式单元格”如果为:自定义公式为 设置值为:=countif(A:A,A1)>1(或将A更改为您选择的列) 设置格式样式。 确保该范围适用于您的列(例如,A1:A100)。 点击完成

在A1:A100单元格中写入的任何内容都将被检查,如果有重复的(出现多次),那么它将被着色。

对于使用逗号(,)作为小数分隔符的区域,参数分隔符很可能是分号(;)。也就是说,尝试:=countif(A:A;A1)>1。

对于多列,使用计数。

我试了所有的方法,没有一个奏效。

只有谷歌应用程序脚本帮助我。

来源: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秒的时间里,我的重复行被着色了。只需要复制脚本。

如果你不知道谷歌应用程序脚本,这个链接可以帮助你:

https://zapier.com/learn/google-sheets/google-apps-script-tutorial/

https://developers.google.com/apps-script/overview

我希望这能有所帮助。

突出显示重复的(在C栏):

=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.)

因此,这就是说,计算C1(当前计算单元格)中在整个列C中的任何内容的出现次数,如果有超过1个(即值有重复),那么:应用高亮(因为公式总的来说,计算结果为TRUE)。

只突出显示第一个副本:

=AND(COUNTIF(C:C, C1) > 1, COUNTIF(C$1:C1, C1) = 1)

解释:这只会突出显示两个COUNTIFs都为TRUE(它们出现在AND()中)。

要计算的第一个项(COUNTIF(C:C, C1) > 1)与第一个示例中完全相同;只有当C1中有一个副本时,它才为TRUE。(请记住,C1实际上是指正在检查的当前行,以确定是否应该突出显示它)。

第二项(COUNTIF(C$1:C1, C1) = 1)看起来类似,但它有三个关键的区别:

它不搜索整个列C(像第一个一样:C:C),而是从第一行开始搜索:C $1 ($强制它逐字地查看第1行,而不是正在计算的任何一行)。

然后它在求值的当前行C1处停止搜索。

最后它说= 1。

因此,只有当当前正在计算的行上面没有重复项时(这意味着它必须是重复项中的第一个),它才会为TRUE。

结合第一个项(仅当该行有重复项时为TRUE),这意味着只有第一个项将被突出显示。

突出显示第二个及以后的重复项:

=AND(COUNTIF(C:C, C1) > 1, NOT(COUNTIF(C$1:C1, C1) = 1), COUNTIF(C1:C, C1) >= 1)

解释:第一个表达式总是相同的(如果当前计算的行完全是重复的,则为TRUE)。

第二项与最后一项完全相同,只是它被否定了:它周围有一个NOT()。所以它忽略了第一种情况。

最后,第三项选择重复的2、3等。COUNTIF(C1:C, C1) >= 1在当前计算的行(C1:C中的C1)处启动搜索范围。然后,只有在这个副本(包括这个副本)下面有一个或多个副本时,它才计算为TRUE(应用高亮):>= 1(它必须是>=而不仅仅是>,否则最后一个副本将被忽略)。

从“文本包含”下拉菜单中选择“自定义公式是:”,并写入:“=countif(A:A, A1) > 1”(不带引号)

我完全按照zolley的建议做了,但应该做一个小修正:使用“自定义公式是”而不是“文本包含”。 然后条件渲染就可以工作了。

@zolley的答案是正确的。只是添加了一个Gif和步骤作为参考。

后转菜单格式>条件格式。 找到格式化单元格如果.. Add =countif(A:A,A1)>1 in field自定义公式为 注意:用您自己的列更改字母A。