can u plz show me full code in excel vba .
it`s a worksheet in excel
Main Topics
Browse All TopicsA B C D
1 Name DateOfBirth IDnumber profession
2 Dave 08/05/2009 0362514 Doctor
3 Dave 08/02/2009 0362514 Doctor
4 sofy 01/02/2009 0326529 Doctor
I need to compare all rows (go through all rows) if all row cells r equal except date then delete row which have the newer date.
in this example, row 1 and row 2 equal except the date . means that row number 2 should be deleted!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Dim START_ROW As Long, END_ROW As Long
Sub Button1_Click()
Dim i As Long, j As Long
START_ROW = 1 '<< Replace it with Starting Row Number of your data
END_ROW = 6 '<< Replace it with last Row Number of your data
For i = START_ROW To END_ROW - 1
For j = i + 1 To END_ROW
If (Sheet1.Cells(i, 2) = Sheet1.Cells(j, 2)) And (Sheet1.Cells(i, 4) = Sheet1.Cells(j, 4)) And (Sheet1.Cells(i, 5) = Sheet1.Cells(j, 5)) Then
If (Sheet1.Cells(i, 3) > Sheet1.Cells(j, 3)) Then
DeleteRow j
Exit For
Else
DeleteRow i
Exit For
End If
End If
Next
Next
End Sub
Sub DeleteRow(row As Long)
Dim i As Long
For i = row + 1 To END_ROW + 1
Sheet1.Cells(i - 1, 1) = Sheet1.Cells(i, 1)
Sheet1.Cells(i - 1, 2) = Sheet1.Cells(i, 2)
Sheet1.Cells(i - 1, 3) = Sheet1.Cells(i, 3)
Sheet1.Cells(i - 1, 4) = Sheet1.Cells(i, 4)
Sheet1.Cells(i - 1, 5) = Sheet1.Cells(i, 5)
Next
END_ROW = END_ROW - 1
End Sub
Business Accounts
Answer for Membership
by: rizwanidreesPosted on 2009-08-05 at 22:38:12ID: 25030338
Use following query to select latest records where matching rows are more than once
SELECT Name, IDNumber, Profession, MAX(DateOfBirth) AS DOB FROM MyTable
GROUP BY Name, IDNumber, Profession
HAVING Count(IDNumber)>1
then use a loop and write following query to delete records
DELETE FROM MyTable WHERE Name='NAME' AND Profession='Profession' AND IDNumber='IDNumber'
AND DateOfBirth<#DOB#