# Excel比较两列并在find时突出显示

``A1 - P7767 A2 - P3443 A3 - P7767 A4 - P8746 A5 - P9435` `

` `B1 - P7767 B2 - P8746` `

### 8 Solutions collect form web for “Excel比较两列并在find时突出显示”

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

• VLOOKUP正在查找单元格A1（第一个参数）对整个列B（\$ B：\$ B）的值，在第一列（这是第三个参数，在这里是冗余的，但是通常VLOOKUP查找表格而不是柱）。 最后一个参数FALSE指定匹配必须精确，而不仅仅是最接近的匹配。
• 如果找不到匹配项，VLOOKUP将返回#ISNA，所以NOT（ISNA（…））对B列中所有匹配的单元格都返回true。

` `=COUNTIF(\$B:\$B,A1)` `

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

1. select两列
2. 单击条件格式
3. 单击加亮单元格规则
4. 点击重复值（默认值应该是OK）
5. 现在重复显示为红色：

A1 – >条件格式 – >单元格的值是B1 – >格式：无论你想要的

Sub 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` `

• 在excel中提取前5个最大值