Comibed Prouct and delete duplicate

farhan11941234

New Member
Joined
Dec 14, 2019
Messages
29
Office Version
  1. 365
Platform
  1. Windows
In Id Column there are duplicate entries but product column is different. i want to combine product line A or A+B or A+B+C in next column and delete duplicates entries in column A.
please see snapshot of spreadsheet.
 

Attachments

  • Sample.png
    Sample.png
    8.7 KB · Views: 16

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to the forum

What does combine mean ? What is the expected result for ?
3222000011 (has A & B)
3222002011 (has A & B & C)

Do you want ..
Column A: 3222000011 Column B: A+B
Column A: 3222002011 Column B: A+B+C
 
Upvote 0
in column C Result Should be A+B 3222000011 and 3222002011 Column B: A+B+C through VBA
 
Upvote 0
So will column A be identical to column C ?
 
Upvote 0
tow entries in column A 32220000011 but Product Cell B2 Value is A and B3 Value B
i Want in C Column A+B and then remove 2nd Duplicate value i.e Row 3 and same pattern goes down to all rows and only unique value remains
 
Upvote 0
thanks for clarification
will update thread later today
 
Upvote 0
Notes
1. Data should be in columns A & B with headers in A1:B1
2. Run macro from sheet containing the data

Result sheet:

Book1
ABC
1ID #ProductCombine Products
2100001AA+B
3100002AA+B+C
4100003AA+B+C+D
5100004AA+B
6100005AA
7100006BB
8100007CC
Sheet1 (2)


Source sheet:

Book1
AB
1ID #Product
2100008E
3100008D
4100003D
5100008C
6100007C
7100003C
8100002C
9100008B
10100006B
11100004B
12100003B
13100002B
14100001B
15100008A
16100005A
17100004A
18100003A
19100002A
20100001A
Sheet1


VBA Code:
Sub farhan11941234()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, Cel As Range, Rng As Range, Prod As Range, F As Long, Addr As String
    Dim MainStr As String, ProdStr As String
  
 'copy to new sheet and remove duplicates
    ActiveSheet.Copy Before:=Sheets(1)
    Set ws = Sheets(1)
    ws.Cells(1, 3) = "Combine Products"
    ws.Range("A:B").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
'sort data by ID and then by Product
    With ws.Sort
        .SortFields.Add Key:=Range("A1"), Order:=xlAscending
        .SortFields.Add Key:=Range("B1"), Order:=xlAscending
        .SetRange Range("A:B")
        .Header = xlYes
        .Apply
    End With
'concatenate strings
    Set Rng = ws.Range("A2", ws.Range("A" & ws.Rows.Count).End(xlUp))
    For Each Cel In Rng
        ProdStr = Cel.Offset(, 1)
        If WorksheetFunction.CountIf(ws.Range("A2", Cel), Cel) = 1 Then
            MainStr = ProdStr
            Set Prod = Cel.Offset(, 2)
        Else
            MainStr = MainStr & "+" & ProdStr   
        End If
        If Cel.Offset(1) <> Cel Then Prod = MainStr
    Next Cel
'remove unwnated rows
    Set Prod = ws.Cells(ws.Rows.Count, 3)
    For Each Cel In Rng.Offset(, 2)
        If Cel = "" Then Set Prod = Union(Prod, Cel)
    Next Cel
    Prod.EntireRow.Delete
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,272
Members
449,219
Latest member
daynle

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