Compare Macro in Excel

Closed
Smitty - 10 Dec 2010 à 17:55
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 11 Dec 2010 à 05:55
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!!


Related:

1 response

venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
11 Dec 2010 à 05:55
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