# Sorting two columns to find duplicates

#### wickyd

##### New Member
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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

#### Lewiy

##### Well-known Member
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``````

#### wickyd

##### New Member
**** Lewiy, that was quick!

Thank you, that is perfect.

wickyd

Replies
3
Views
347
Replies
5
Views
198
Replies
1
Views
282
Replies
3
Views
95
Replies
4
Views
113

1,181,102
Messages
5,928,062
Members
436,586
Latest member
latintxn

### 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.

### Which adblocker are you using?

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

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