简体   繁体   English

Excel 比较两列并突出显示重复项

[英]Excel compare two columns and highlight duplicates

I have an excel file with 10,000 rows in column A some values are the same.我有一个 excel 文件,A 列中有 10,000 行,有些值是相同的。

Example:例子:

A1 - P7767

A2 - P3443

A3 - P7767

A4 - P8746

A5 - P9435

etc... ETC...

I then have another column with 100 rows which have some of the values found in column A,然后我有另一列有 100 行,其中一些值在 A 列中找到,

B1 - P7767

B2 - P8746

etc... ETC...

I need to highlight all cells in column A where the value is found in any of the values in column B我需要突出显示 A 列中的所有单元格,其中在 B 列中的任何值中都可以找到该值

So basically column B checks to see if it can find the same value anywhere in column A, if true highlight the cell leaving any cells white when the value is not found in column B所以基本上 B 列检查它是否可以在 A 列中的任何位置找到相同的值,如果为真,则突出显示该单元格,当在 B 列中找不到该值时,将所有单元格留白

I hope I have explained this well, I have done some research and I believe I need to use conditional formatting to get this result but I am really stuck on the formula to use and cannot seem to find an example online (Maybe I am not searching the correct term as I'm not sure on what this is exactly called)我希望我解释得很好,我做了一些研究,我相信我需要使用条件格式来获得这个结果,但我真的坚持要使用的公式并且似乎无法在网上找到示例(也许我不是在搜索正确的术语,因为我不确定这到底叫什么)

There may be a simpler option, but you can use VLOOKUP to check if a value appears in a list (and VLOOKUP is a powerful formula to get to grips with anyway).可能有一个更简单的选项,但您可以使用 VLOOKUP 检查值是否出现在列表中(并且 VLOOKUP 是一个强大的公式,无论如何都要掌握)。

So for A1, you can set a conditional format using the following formula:因此对于 A1,您可以使用以下公式设置条件格式:

=NOT(ISNA(VLOOKUP(A1,$B:$B,1,FALSE)))

Copy and Paste Special > Formats to copy that conditional format to the other cells in column A. Copy and Paste Special > Formats 将该条件格式复制到 A 列中的其他单元格。

What the above formula is doing:上面的公式在做什么:

  • VLOOKUP is looking up the value of Cell A1 (first parameter) against the whole of column B ($B:$B), in the first column (that's the 3rd parameter, redundant here, but typically VLOOKUP looks up a table rather than a column). VLOOKUP 在第一列中查找单元格 A1(第一个参数)对整个 B 列($B:$B)的值(这是第三个参数,这里是多余的,但通常 VLOOKUP 查找表而不是柱子)。 The last parameter, FALSE, specifies that the match must be exact rather than just the closest match.最后一个参数 FALSE 指定匹配必须是精确的,而不仅仅是最接近的匹配。
  • VLOOKUP will return #ISNA if no match is found, so the NOT(ISNA(...)) returns true for all cells which have a match in column B.如果未找到匹配项,VLOOKUP 将返回 #ISNA,因此 NOT(ISNA(...)) 对 B 列中具有匹配项的所有单元格返回 true。

A simple formula to use is一个简单的公式是

=COUNTIF($B:$B,A1)

Formula specified is for cell A1.指定的公式适用于单元格 A1。 Simply copy and paste special - format to the whole of column A只需将特殊格式复制并粘贴到整个 A 列

NOTE: You may want to remove duplicate items (eg duplicate entries in the same column) before doing these steps to prevent false positives.注意:您可能希望在执行这些步骤之前删除重复项(例如同一列中的重复条目)以防止误报。

  1. Select both columns Select 两列
  2. click Conditional Formatting单击条件格式
  3. click Highlight Cells Rules单击突出显示单元格规则
  4. click Duplicate Values (the defaults should be OK)单击重复值(默认值应该没问题)
  5. Duplicates are now highlighted in red:重复项现在以红色突出显示:

在此处输入图像描述

在此处输入图像描述

The easiest way to do it, at least for me, is:至少对我来说,最简单的方法是:

Conditional format-> Add new rule->Set your own formula:条件格式-> 添加新规则-> 设置您自己的公式:

=ISNA(MATCH(A2;$B:$B;0))

Where A2 is the first element in column A to be compared and B is the column where A's element will be searched.其中 A2 是要比较的 A 列中的第一个元素,B 是将在其中搜索 A 的元素的列。

Once you have set the formula and picked the format, apply this rule to all elements in the column.设置公式并选择格式后,将此规则应用于列中的所有元素。

Hope this helps希望这可以帮助

A1 --> conditional formatting --> cell value is B1 --> format: whatever you want A1 --> 条件格式 --> 单元格值为 B1 --> 格式:随便你

hope that helps希望有帮助

Suppose you want to compare a column A and column H in a same spreadsheet.假设您要比较同一电子表格中的 A 列和 H 列。

You need to go another column next to these 2 columns and paste this formula: =(Sheet1:A:A=Sheet1.HH) this will display FALSE or TRUE in the column .您需要 go 这 2 列旁边的另一列并粘贴此公式:=(Sheet1:A:A=Sheet1.HH) 这将在列中显示 FALSE 或 TRUE。 So you can use this new column to color the non matching values using conditional color formatting feature .因此,您可以使用此新列使用条件颜色格式设置功能为不匹配的值着色。

I was trying to compare AB columns and highlight equal text, but usinng the obove fomrulas some text did not match at all.我试图比较 AB 列并突出显示相同的文本,但是使用上面的公式有些文本根本不匹配。 So I used form ( VBA macro to compare two columns and color highlight cell differences ) codes and I modified few things to adapt it to my application and find any desired column (just by clicking it).所以我使用表单( VBA 宏来比较两列和颜色突出显示单元格差异)代码,我修改了一些东西以适应我的应用程序并找到任何所需的列(只需单击它)。 In my case, I use large and different numbers of rows on each column.就我而言,我在每一列上使用大量不同数量的行。 Hope this helps:希望这可以帮助:

Sub ABTextCompare()子 ABTextCompare()

Dim Report As Worksheet
Dim i, j, colNum, vMatch As Integer
Dim lastRowA, lastRowB, lastRow, lastColumn As Integer
Dim ColumnUsage As String
Dim colA, colB, colC As String
Dim A, B, C As Variant

Set Report = Excel.ActiveSheet
vMatch = 1

'Select A and B Columns to compare
On Error Resume Next
 Set A = Application.InputBox(Prompt:="Select column to compare", Title:="Column A", Type:=8)
  If A Is Nothing Then Exit Sub
colA = Split(A(1).Address(1, 0), "$")(0)
 Set B = Application.InputBox(Prompt:="Select column being searched", Title:="Column B", Type:=8)
   If A Is Nothing Then Exit Sub
  colB = Split(B(1).Address(1, 0), "$")(0)
 'Select Column to show results
 Set C = Application.InputBox("Select column  to show results", "Results", Type:=8)
    If C Is Nothing Then Exit Sub
  colC = Split(C(1).Address(1, 0), "$")(0)

'Get Last Row
lastRowA = Report.Cells.Find("", Range(colA & 1), xlFormulas, xlByRows, xlPrevious).Row - 1 ' Last row in column A
lastRowB = Report.Cells.Find("", Range(colB & 1), xlFormulas, xlByRows, xlPrevious).Row - 1 ' Last row in column B

 Application.ScreenUpdating = False
'***************************************************
For i = 2 To lastRowA
      For j = 2 To lastRowB
          If Report.Cells(i, A.Column).Value <> "" Then
              If InStr(1, Report.Cells(j, B.Column).Value, Report.Cells(i, A.Column).Value, vbTextCompare) > 0 Then
                  vMatch = vMatch + 1
                  Report.Cells(i, A.Column).Interior.ColorIndex = 35 'Light green background
                  Range(colC & 1).Value = "Items Found"
                  Report.Cells(i, A.Column).Copy Destination:=Range(colC & vMatch)
                  Exit For
              Else
                  'Do Nothing
              End If
          End If
      Next j
  Next i
If vMatch = 1 Then
    MsgBox Prompt:="No Itmes Found", Buttons:=vbInformation
End If
'***************************************************
Application.ScreenUpdating = True

End Sub结束子

Don't wana do soo much work guyss.. Just Press Ctr and select Colum one and Press Ctr and select colum two.伙计们,不要做太多工作。只需按 Ctr 和 select 第一列,然后按 Ctr 和 select 第二列。 Then click conditional formatting -> Highlight Cell Rules -> Equel To.然后单击条件格式 -> 突出显示单元格规则 -> Equel To。

and thats it.就是这样。 your done.你完成了。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM