View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Compare & Delete in Excel

How about:

Option Explicit
Sub testme01()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim res As Variant

With ActiveSheet
FirstRow = 1 'no headers in row 1???
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
res = Application.Match(.Cells(iRow, "B").Value, .Range("a:a"), 0)
If IsError(res) Then
'keep it--it's unique
Else
.Cells(res, "B").Delete shift:=xlShiftUp
End If
Next iRow
End With

End Sub




smittydotbat wrote:

I am new to the excel programming with VB and I need some help...

I have an excel workbook with one sheet. In one column I have a list of
names.
On another column I have another list of names.

What I am trying to accomplish is that when a button click event is
invoked, I would like the cells in the first column to be compared
against the other column. When it does this compare it will strip out
the duplicates in column two (which are also in column one) and leave
what's left.

Scenario:

*Before the compare*

Column A Column B
x x
xy xyy
xyz xyz
yzx yzx

*After the Compare*

Column A Column B
x xyy
xy
xyz
yzx

If anyone can help me with this I would greatly be appreciative.

--
smittydotbat
------------------------------------------------------------------------
smittydotbat's Profile: http://www.excelforum.com/member.php...o&userid=15232
View this thread: http://www.excelforum.com/showthread...hreadid=268648


--

Dave Peterson