How to combine rows with duplicate info into one based on a column

texhorn92

New Member
Joined
Jul 1, 2017
Messages
10
I'm looking for a more efficient way of combining possible duplicate rows depending on the column "Product." Some rows will not have duplicates. Here is a sample of the data I'm working with. In reality, I am working with thousands of these rows and over 40 columns


ProductStore AStore BStore C
KOMBUCHA VANILLA3.99 (2.99 SAL)3.99 (2.99 SAL)3.99 (2.99 SAL)
KOMBUCHA RED3.99 (2.99 SAL)3.99 (2.99 SAL)3.99 (2.99 SAL)
YOGURT DRINK5.99 (4.79 SAL)
YOGURT DRINK5.99 (4.79 SAL)5.99 (4.79 SAL)
YOGURT BANANA 4PK5.99 (4.79 SAL)
YOGURT BANANA 4PK5.99 (4.79 SAL)5.99 (4.79 SAL)
YOGURT BERRY 4PK5.99 (4.79 SAL)
COFFEE3.99 (3.39 SAL)3.99 (3.39 SAL)3.99 (3.39 SAL)

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>


After combining the duplicate rows (using Product), I would achieve something like this:


ProductStore AStore BStore C
KOMBUCHA VANILLA3.99 (2.99 SAL)3.99 (2.99 SAL)3.99 (2.99 SAL)
KOMBUCHA RED3.99 (2.99 SAL)3.99 (2.99 SAL)3.99 (2.99 SAL)
YOGURT DRINK5.99 (4.79 SAL)5.99 (4.79 SAL)5.99 (4.79 SAL)
YOGURT BANANA 4PK5.99 (4.79 SAL)5.99 (4.79 SAL)5.99 (4.79 SAL)
COFFEE3.99 (3.39 SAL)3.99 (3.39 SAL)3.99 (3.39 SAL)

<colgroup><col><col><col><col><col></colgroup><tbody>
</tbody>


Any ideas on how I could make this process more efficient. I am currently doing this manually and it is very painful. Thanks!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try this for results on sheet 2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG15Jul45
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, Dic [COLOR="Navy"]As[/COLOR] Object, rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Ray = ActiveSheet.UsedRange
ReDim nRay(1 To UBound(Ray, 1), 1 To UBound(Ray, 2))
[COLOR="Navy"]Set[/COLOR] Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
     [COLOR="Navy"]For[/COLOR] n = 1 To UBound(Ray, 1)
           [COLOR="Navy"]If[/COLOR] Not Dic.Exists(Ray(n, 1)) [COLOR="Navy"]Then[/COLOR]
                rw = rw + 1
                [COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray, 2)
                    nRay(rw, Ac) = Ray(n, Ac)
                [COLOR="Navy"]Next[/COLOR] Ac
                Dic.Add Ray(n, 1), rw
            [COLOR="Navy"]Else[/COLOR]
                [COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray, 2)
                    [COLOR="Navy"]If[/COLOR] IsEmpty(nRay(Dic(Ray(n, 1)), Ac)) [COLOR="Navy"]Then[/COLOR]
                       nRay(Dic(Ray(n, 1)), Ac) = Ray(n, Ac)
                    [COLOR="Navy"]End[/COLOR] If
                [COLOR="Navy"]Next[/COLOR] Ac
            [COLOR="Navy"]End[/COLOR] If
     [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2").Range("A1").Resize(Dic.Count, UBound(Ray, 2))
    .Value = nRay
    .Columns.AutoFit
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,265
Members
449,149
Latest member
mwdbActuary

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