Duplicate multiples over different columns

tbollo

New Member
Joined
Apr 16, 2018
Messages
19
Hello,

My data contains three columns:

'Product 1', 'Product 2' and 'Quantity' - Quantity represents the number of times 'Product 1' and 'Product 2' were purchased together:


ABC
1
Product 1Product 2Quantity
2AB30
3BA30
4CA10
5DC5
6ED17
7FA11
8AC10
9GD17
10EA10

<tbody>
</tbody>


In the above, rows 2 and 3 are the same combination of products with the same quantity. I would like to remove one of these duplicates and keep just one in the list.

NB: the duplicate combinations are not necessarily next to each other, as shown by rows 4 and 8.

Any help?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG17Apr06
[COLOR="Navy"]Dim[/COLOR] cell [COLOR="Navy"]As[/COLOR] Range, Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Txt [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]With[/COLOR] Range("A2", Cells(Rows.Count, "B").End(xlUp))
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] cell [COLOR="Navy"]In[/COLOR] .Columns(2).Cells
      [COLOR="Navy"]With[/COLOR] cell
        [COLOR="Navy"]If[/COLOR] .Value2 < .Offset(, -1).Value2 [COLOR="Navy"]Then[/COLOR]
          .Cut
          .Offset(, -1).Insert
        [COLOR="Navy"]End[/COLOR] If
      [COLOR="Navy"]End[/COLOR] With
    [COLOR="Navy"]Next[/COLOR] cell
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
    [COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
        .CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    Txt = Dn.Value & Dn.Offset(, 1).Value & Dn.Offset(, 2).Value
        [COLOR="Navy"]If[/COLOR] Not .Exists(Txt) [COLOR="Navy"]Then[/COLOR]
            .Add Txt, Nothing
        [COLOR="Navy"]Else[/COLOR]
            [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Set[/COLOR] nRng = Dn
            [COLOR="Navy"]Else[/COLOR]
                [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
another VBA option
- run from sheet containing the data
Code:
Sub RemoveDup()
Application.ScreenUpdating = False
    Dim LastRow As Long, ws As Worksheet
    Set ws = ActiveSheet
    On Error Resume Next
    ws.ShowAllData
    LastRow = Range("A1").CurrentRegion.Rows.Count
    Range("D2").Formula = "=COUNTIFS($A$2:A2,A2,$B$2:B2,B2,$C$2:C2,C2)+COUNTIFS($A$2:A2,B2,$B$2:B2,A2,$C$2:C2,C2)"
    Range("D2").Copy ws.Range("D2:D" & LastRow)
    Range("A:D").AutoFilter Field:=4, Criteria1:=">1"
    Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Rows.EntireRow.Delete
    ws.ShowAllData
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
or without VBA
- same method as VBA solution

add formula to D2 and copy down
=COUNTIFS($A$2:A2,A2,$B$2:B2,B2,$C$2:C2,C2)+COUNTIFS($A$2:A2,B2,$B$2:B2,A2,$C$2:C2,C2)

Filter the data with column D >1
Select & delete those rows
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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