Sorting two columns to find duplicates

wickyd

New Member
Joined
Dec 21, 2004
Messages
3
Hi folx

I have a sorting query.

How do I go from:

Code:
a        d
s        e
w        f
e        y
d        m
r        
f
t
h
y

to

Code:
a         
s         
w        
e        e
d        d
r        
f        f
t
h
y        y
         m

1. The real data is email addresses.
2. Column B is a smaller set of data that Column A.
3. Column B will have entries that are not included in Column A, which I would like to be displayed after Column A ends.

Any help would be greatly appreciated.

Thank you.

Kind regards
wickyd
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this macro, it requires that your data is in columns A and B and have a spare column C:
Code:
Sub SortMe()
Dim limita As Long
Dim limitb As Long
Dim a As Long
Dim b As Long
Dim flag As Boolean
Dim testa As Long
Dim testb As Long
limita = Cells(Rows.Count, 1).End(xlUp).Row
limitb = Cells(Rows.Count, 2).End(xlUp).Row
For b = 1 To limitb
    flag = False
    For a = 1 To limita
        If Cells(b, 2) = Cells(a, 1) Then
            Cells(a, 3) = Cells(b, 2)
            flag = True
        End If
    Next a
    If flag = False Then
        testa = Cells(Rows.Count, 1).End(xlUp).Row
        testb = Cells(Rows.Count, 3).End(xlUp).Row
        If testa > testb Then
            Cells(testa + 1, 3) = Cells(b, 2)
            Else
                Cells(testb + 1, 3) = Cells(b, 2)
        End If
    End If
Next b
Columns(2).Delete shift:=xlToLeft
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,209
Members
448,874
Latest member
b1step2far

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