View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Creating Code??

The code is a little complicated because I didn't know if you would find more
than two rows that met the criteria. It sorted the data to get the rows in
order to make the code simplier. If you had two rows where the hlduniq and a
thrid line that didn't then only the 2nd and 3rd will be moved.

The code expects the source data to be in Sheet1 and it will move the data
that meets the criteria to Sheet2.

Sub GetDuplicates()

With Sheets("Sheet1")
'First Sort Data
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
Set SortRange = .Rows("1:" & LastRow)
SortRange.Sort _
key1:=.Range("E1"), _
order1:=xlAscending, _
key2:=.Range("F1"), _
order2:=xlAscending, _
key3:=.Range("A1"), _
order3:=xlAscending, _
header:=xlYes

NewRow = 1
RowCount = 2
Start = RowCount
Duplicate = False
Do While .Range("A" & RowCount) < ""
If .Range("E" & RowCount) = _
.Range("E" & (RowCount + 1)) And _
Left(.Range("F" & RowCount), 3) = _
Left(.Range("F" & (RowCount + 1)), 3) And _
.Range("A" & RowCount) < _
.Range("A" & (RowCount + 1)) Then

Duplicate = True
Else
If Duplicate = True Then
Duplicate = False
.Rows(Start & ":" & RowCount).Copy _
Destination:=Sheets("Sheet2").Rows(NewRow)
NewRow = NewRow + (RowCount - Start) + 1
Else
Start = RowCount + 1
End If
End If
RowCount = RowCount + 1
Loop

If Duplicate = True Then
Duplicate = False
.Rows(Start & ":" & RowCount).Copy _
Destination:=Sheets("Sheet2").Rows(NewRow + 1)
End If
End With

End Sub


"Jcraig713" wrote:

My spreadsheet data look like this:

A B C D E F G
H
hlduniq Sclname StuLast Stufirst house# StrNam City Zip
99 BldgA Black John 100 Second Detroit 48330
100 BldgA Smith Jane 133 Main Detroit 48332
100 BldgB Smith John 133 Main Detroit 48332
101 BldgA Doe Jane 1001 First Detroit 48331
102 BldgB Doe John 1001 First Detroit 48332

What I would like the code to do is to return just the two rows (the Doe's
on the bottom) that the house number and the first three digits of the street
name are the same, but the household unique ID differs. In my system, this
is a duplicate address that needs to be amended to one house unique. I just
need a way to not have to manually look through 10,000 records by hand. Can
this be done? Can you help?