How do I identify and delete rows with matching data mixed between multiple columns?

ChrisJP

New Member
Joined
Jan 8, 2018
Messages
6
Example:
Column 1Column 2
Row 1ABC123MNO456
Row 2ZZZ987YYY789
Row 3MNO456ABC123

<tbody>
</tbody>

How could I identify Row 1 and Row 3 as being matches/duplicates rows, when the columns may have the data swapped?

Ideally I would want the a VB script or way to delete the Row 3 automatically since it is a duplicate.

This may be basic, but I've been searching for a while now and can't quite find the answer. I appreciate any help you can provide.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Code:
Sub t()
Dim lr As Long, i As Long, fn As Range
    With ActiveSheet
        lr = .Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
        For i = lr To 2 Step -1
            Set fn = .Range("B:B").Find(.Cells(i, 1).Value, , xlValues, xlWhole)
                If Not fn Is Nothing Then
                    If fn.Offset(, -1).Value = .Cells(i, 2).Value Then
                        .Rows(i).Delete
                    End If
                End If
        Next
    End With
End Sub
 
Upvote 0
JLGWhiz,

This seems to work for a portion of my data, but it seems to fail at a certain point. On my data below, it fails to recognize G006134/G004402 as a duplicate. Any ideas why this might happen? I appreciate the help!

C1
C2
B34558
16612
B4162768418
G00065986130
G00159477539
G00222496232
G002544G004514
G004514G002544
G002771G002772
G002771L49435
G002772G002771
G002772L49435
G002814G004402
G002814G006134
G002814L51316
G004402
G006134
G004402G002814
G004402L51316
G004402G006031
G006031G004402
G006031G006134
G006134
G004402
G006134G002814
G006134L51316
G006134G006031
L51316G002814
L51316G004402
L51316G006134
G005639L55069
G005639L58082
G006683L58082
L55069G005639
L55069
L58082
L58082G005639
L58082G006683
L58082L55069

<colgroup><col style="mso-width-source:userset;mso-width-alt:2121;width:44pt" width="58"> <col style="mso-width-source:userset;mso-width-alt:2121;width:44pt" width="58"> </colgroup><tbody>
</tbody>
 
Upvote 0
Check for Ohs entered for Zeros. O v. 0
 
Upvote 0
Did a search for O vs Zero, no letter O.

I would think it has to be a binary difference of some type, if all the others worked but that one set of characters. Try retyping them and see if they still won't match. I am assuming that you added the bold font and underline for illustration purposes. If not, that is your problem. The underline will not match, but the bold font should.
 
Last edited:
Upvote 0
I was wrong, it should recognize the match, even with the underline.

Try this mod

Code:
Sub t()
Dim lr As Long, i As Long, fn As Range
    With ActiveSheet
        lr = .Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
        For i = lr To 2 Step -1
            Set fn = .Range("B:B").Find(.Cells(i, 1).Value, , xlValues, xlWhole)
                If Not fn Is Nothing Then
                    If [COLOR=#FF0000]Trim[/COLOR](fn.Offset(, -1).Value) = [COLOR=#FF0000]Trim[/COLOR](.Cells(i, 2).Value) Then
                        .Rows(i).Delete
                    End If
                End If
        Next
    End With
End Sub
 
Last edited:
Upvote 0
The mod ended with the same result, still missed some.

The underline was just to highlight one of the examples. There were more missed, the just the one.

Also missed:
L55069/L58082 and L58082/L55069
L51316/G004402 and G004402/L51316
 
Upvote 0
Well, it has me stymied. I thought the Trim function would fix it if it was not a binary problem. If I think of anything else I will post back.

One other thing. Do you have duplicate entries in column A? Never mind, I see that you do. I think I can fix the problem.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,507
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top