View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rowan Drummond[_3_] Rowan Drummond[_3_] is offline
external usenet poster
 
Posts: 414
Default appending records

Hi Michael

If you don't mind having the data sorted then this is one way to get rid
of duplicates (assumes we are still talking about the range ("A2:D100"):

Sub dups()
Dim i As Integer
Range("A2:D100").Sort Key1:=Range("B2"), Order1:=xlAscending _
, Key2:=Range("C2"), Order2:=xlAscending, Header:=xlNo
For i = 100 To 2 Step -1
If Cells(i, 2).Value = Cells(i - 1, 2).Value And _
Cells(i, 3).Value = Cells(i - 1, 3).Value Then
Rows(i).Delete
End If
Next i
End Sub

Regards
Rowan

wrote:
Rowan,

Thanks for the code. I'll work on figuring out how it works (I don't
like to 'copy and paste'. I like to learn something along the way).

Here's an example:

datacol1 datacol2 datacol3 datacol4
row1 A B C C
row2 A C B D
row3 Z B C A
row4 Y C B H

In this example, I want to match on datacol2 and datacol3. Based on
that,
row1 = row3 and row2 = row4. I dissregard datacol1 and datacol4. I
want to keep row1 and row2 in this scenerio.

Thanks.
-Michael.