Compare Macro in Excel [Closed]

Report
-
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
-
Hello,

I am trying to create a macro in Excel 2003 that will compare data in Column A to Column B. The cells that are in column A and B will vary each time. I need to find duplicates entries between Column A & B and then output the NON-Duplicates into Column D, leaving Column C blank. It also would be nice to have Column D bolded and change color but that is the least of my worries at his point. Please help!!


1 reply

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
797
supposse the data is similar to the follwing from A1 down and in column B(NO header row)

a a
s d
d g
f
g
h


now try this macro

Sub test()
Dim r As Range, c As Range, cfind As Range, dest As Range, x As String
Columns("D:D").Delete
Set r = Range("A1").CurrentRegion
For Each c In r
If WorksheetFunction.CountIf(r, c.Value) = 1 Then
c.Copy
Set dest = Cells(Rows.Count, "D").End(xlUp).Offset(1, 0)
dest.PasteSpecial
End If
Next c
End Sub

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!