|Post from 2009 by DerbyDad03 about sorting pairings in Excel:|
Assuming your data is already sorted so that the duplicates follow one another as in your example, try this code:
What it does is check each item in column B (the bar code) and compare it to the item above it. If they match, it deletes both rows.
When you are deleting items from a list in Excel you have to start at the bottom and work up because if you delete a row on the way down, the counter will increment and skip the row that was moved up after the deletion.
The error checking is used to handle the error that will occur when you reach Row 1. The code will try to check Row (1-1) (Row 0) and throw up an error. The code assumes that once it throws up the error, it must be at Row 1 and therefore done.
'Determine the number of items in column B
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
On Error GoTo Done
'Loop through rows, starting at the bottom
For delRow = lastRow To 1 Step -1
'If duplicates are found, delete both rows
If Cells(delRow, 1) = Cells(delRow - 1, 1) Then
Cells(delRow - 1, 1).EntireRow.Delete