Excel compare two columns and highlight duplicates

前端 未结 8 736
春和景丽
春和景丽 2021-01-30 02:45

I have an excel file with 10,000 rows in column A some values are the same.

Example:

A1 - P7767

A2 - P3443

A3 - P7767

A4 - P8746

A5 - P9435


        
相关标签:
8条回答
  • 2021-01-30 02:46

    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
    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:

    0 讨论(0)
  • 2021-01-30 02:46

    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.

    Once you have set the formula and picked the format, apply this rule to all elements in the column.

    Hope this helps

    0 讨论(0)
  • 2021-01-30 02:48

    A simple formula to use is

    =COUNTIF($B:$B,A1)
    

    Formula specified is for cell A1. Simply copy and paste special - format to the whole of column A

    0 讨论(0)
  • 2021-01-30 02:52

    Suppose you want to compare a column A and column H in a same spreadsheet .

    You need to go another column next to these 2 columns and paste this formula : =(Sheet1!A:A=Sheet1!H:H) this will display FALSE or TRUE in the column . So you can use this new column to color the non matching values using conditional color formatting feature .

    0 讨论(0)
  • 2021-01-30 03:02

    I was trying to compare A-B columns and highlight equal text, but usinng the obove fomrulas some text did not match at all. 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). In my case, I use large and different numbers of rows on each column. Hope this helps:

    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
    

    End Sub

    0 讨论(0)
  • 2021-01-30 03:11

    A1 --> conditional formatting --> cell value is B1 --> format: whatever you want

    hope that helps

    0 讨论(0)
提交回复
热议问题