NamssoB
Board Regular
- Joined
- Jul 8, 2005
- Messages
- 74
- Office Version
-
- 365
- 2016
- Platform
-
- Windows
Here's something I need help with. I need to delete entire rows based on duplicate entries in specific cells. Here are the details:
I have a list of "membership records" in the following format (generated from a database report):
MemberID First Last Age Group
02100319-01 Mildred Lopez Adult
02101485-01 Shelton Hawkins Adult
02103489-01 John Rivera Adult
02103489-02 Traci Rivera Adult
02106796-01 Jordan Chanski Adult
02106796-02 Gabrielle Chanski Adult
02109301-01 Shavon Lofton Adult
02109301-02 Charles Holder Adult
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
(Note that Left(MemberID,8) is what I'm looking at. The Right x2 character could be anything)
I need to delete/keep rows based on the following rules:
1) If (Left(MemberID,8) is unique (there is only one), DELETE ROW
2) If there are TWO identical Left(MemberID,8), DELETE BOTH ROWS
3) 3 or more, keep all of them
Basically, this is a giant database report of memberships, and a maximum of TWO people can be on a membership. So if I find ONE or TWO, I want them removed from the report (they are valid). When the code is finished processing, all the should be left are those that have 3 or more (there could be any number of people listed under one membership, so technically there is no maximum).
In the data above, only the last three rows shown should remain (three identical Left(MemberID,8) entries).
BONUS points if you can figure out how to insert a "separator" row between the groups of MemberID's that remain, or even better, alternate the background color of each unique Left(MemberID,8) group. For example:
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
---------------------------------------------------
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
---------------------------------------------------
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
FYI, I started with the following code, but then realized Iw as way over my head.
I have a list of "membership records" in the following format (generated from a database report):
MemberID First Last Age Group
02100319-01 Mildred Lopez Adult
02101485-01 Shelton Hawkins Adult
02103489-01 John Rivera Adult
02103489-02 Traci Rivera Adult
02106796-01 Jordan Chanski Adult
02106796-02 Gabrielle Chanski Adult
02109301-01 Shavon Lofton Adult
02109301-02 Charles Holder Adult
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
(Note that Left(MemberID,8) is what I'm looking at. The Right x2 character could be anything)
I need to delete/keep rows based on the following rules:
1) If (Left(MemberID,8) is unique (there is only one), DELETE ROW
2) If there are TWO identical Left(MemberID,8), DELETE BOTH ROWS
3) 3 or more, keep all of them
Basically, this is a giant database report of memberships, and a maximum of TWO people can be on a membership. So if I find ONE or TWO, I want them removed from the report (they are valid). When the code is finished processing, all the should be left are those that have 3 or more (there could be any number of people listed under one membership, so technically there is no maximum).
In the data above, only the last three rows shown should remain (three identical Left(MemberID,8) entries).
BONUS points if you can figure out how to insert a "separator" row between the groups of MemberID's that remain, or even better, alternate the background color of each unique Left(MemberID,8) group. For example:
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
---------------------------------------------------
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
---------------------------------------------------
02109638-01 Kendra Amaya Adult
02109638-02 Kevin Amaya Adult
02109638-03 Kassie Amaya Adult
FYI, I started with the following code, but then realized Iw as way over my head.
Code:
Do While Roffset < lastrow
If Left(ActiveCell.Offset(Roffset, 0).Value, 8) = Left(ActiveCell.Offset(Roffset + 1, 0).Value, 8) Then
If Left(ActiveCell.Offset(Roffset + 1, 0).Value, 8) = Left(ActiveCell.Offset(Roffset + 2, 0).Value, 8) Then
' KEEPER
Else
ActiveCell.Offset(Roffset, 0).EntireRow.Delete
ActiveCell.Offset(Roffset + 1, 0).EntireRow.Delete
End If
Else
ActiveCell.Offset(Roffset, 0).EntireRow.Delete
End If
Roffset = Roffset + 1
Loop