Compare data from 2 columns pull unique rows

jeffmoseler

Well-known Member
Joined
Jul 16, 2004
Messages
540
I would like to compare 2 separate columns and list out unique rows in another sheet.

Code:
Column 1         Column 2    Column 3       Column 4      Column 5
MOW204000235	1	       No	      No	Vehicle Maint.
MOW204000235	1	       Yes            No	Driver Fitness
MOW204000235	1	       No	      Yes        Vehicle Maint.
OH3260013363	3	       Yes            No	Driver Fitness
OH3260013363	3	       Yes            No	Driver Fitness
MOW204000155	1	       No	      Yes        Vehicle Maint.
MOW204000155	1	       No	      No	Unsafe Driving
MOW204000155	1	       Yes           Yes        Driver Fitness
MOW204000155	1	       No	      Yes        Driver Fitness
I would like the code to compare Column 1 and Column 5 and list on another sheet the data from those rows.

Results
Code:
Column 1            Column 2    
MOW204000235     Vehicle Maint.
MOW204000235     Driver Fitness
OH3260013363      Driver Fitness
MOW204000155     Vehicle Maint.
MOW204000155     Unsafe Driving
MOW204000155     Driver Fitness
I can find tons of stuff that compares the two rows as if they contained the same data, but nothing if contains different data. Also, ignoring the 3 columns in the creates other issues. Thanks for the help.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
How about
Code:
Sub MoveDupes()
   Dim Cl As Range
   Dim Valu As String
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         Valu = Cl.Value & "|" & Cl.Offset(, 4).Value
         If Not .Exists(Valu) Then .Add Valu, Array(Cl.Value, Cl.Offset(, 4).Value)
      Next Cl
      Sheets("[COLOR=#ff0000]Summary[/COLOR]").Range("A1").Resize(.Count).Value = Application.Transpose(.keys)
      Sheets("[COLOR=#ff0000]Summary[/COLOR]").Range("A1").Resize(.Count).TextToColumns Destination:=Sheets("[COLOR=#ff0000]Summary[/COLOR]").Range("A1"), _
         DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1), Array(2, 1))
   End With
End Sub
Change sheet name in red to match your output sheet
 
Upvote 0
If I understand the assignment, and assuming that your info is in columns from "A" to "E", I believe this should do the trick although you will probably have to make some adjustments...

Code:
Sub CompareColumns()

    Dim LastRow As Long, x As Long
    
    ActiveSheet.Columns("A:E").Copy
        Worksheets.Add after:=ActiveSheet
        ActiveSheet.Range("A1").PasteSpecial
        
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    Range("F1").Value = "Combined info"
    
    For x = 2 To LastRow
        Range("F" & x).Value = Range("A" & x).Value & Range("E" & x).Value
    
    Next x
    
    ActiveSheet.UsedRange.RemoveDuplicates Columns:=6, Header:=xlYes
    
    ActiveSheet.Range("B:D,F:F").EntireColumn.Delete
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top