Merging cells and retaining data

Tom Allen

Board Regular
Joined
Sep 26, 2014
Messages
92
post_title

<tbody>
</tbody>
post_excerpt

<tbody>
</tbody>
post_status

<tbody>
</tbody>
visibility

<tbody>
</tbody>
stock_status

<tbody>
</tbody>
regular_price

<tbody>
</tbody>
tax:product_cat

<tbody>
</tbody>
attribute: pa_model

<tbody>
</tbody>
attribute: pa_alternative-part-numbers

<tbody>
</tbody>
attribute: pa_part-type

<tbody>
</tbody>
example product A

<tbody>
</tbody>
screw
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
0.18

<tbody>
</tbody>
CommanderCommanderScrew-Bottom
example product A

<tbody>
</tbody>
screw
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
0.18

<tbody>
</tbody>
Highway 3Highway 3Screw-Bottom
example product A

<tbody>
</tbody>
screw
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
0.18

<tbody>
</tbody>
HighwayHighwayScrew-Bottom
example product Bblade
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
20ParkwayParkwayblade7
example product Bblade
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
20Parkway2Parkway2blade7
example product Cdisc
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
15MountedMountedblade10
example product Cdisc
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
15Mounted5Mounted5blade10
example product Cdisc
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
15Mounted9Mounted9blade11
example product Cdisc
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
15Motor7Motor7blade15

<tbody>
</tbody>

Hi I've got a set of product data, as demonstrated above. I somehow need to merge the products if they are duplicated while retaining certain data.

So for example if example product A is found more than once then I need to merge all instances of example product A into one row.

The tax:product_cat column and attribute: pa_model column will always contain different values for each instance of the same product. I can just replicate the attribute: pa_part-type column from the tax:product_cat column so that cab be ignored. However I need to merge the tax:product_cat column and retain all values.

So in the example data shown above for example product A the tax:product_cat column would merge to show Commander|Highway 3|Highway

The attribute: pa_part-type column will sometimes be different as well. However I only need to keep the values if they are different. For example the example product A row would just show Screw-Bottom as they are all the same. However example product C would show blade10|blade11|blade15

Below is an example of how the above data should look

post_title

<tbody>
</tbody>
post_excerpt

<tbody>
</tbody>
post_status

<tbody>
</tbody>
visibility

<tbody>
</tbody>
stock_status

<tbody>
</tbody>
regular_price

<tbody>
</tbody>
tax:product_cat

<tbody>
</tbody>
attribute: pa_model

<tbody>
</tbody>
attribute: pa_alternative-part-numbers

<tbody>
</tbody>
attribute: pa_part-type

<tbody>
</tbody>
example product A

<tbody>
</tbody>
screw
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
0.18

<tbody>
</tbody>
Commander|Highway 3|HighwayCommander|Highway 3|HighwayScrew-Bottom
example product Bblade
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
20Parkway|Parkway2Parkway|Parkway2blade7
example product Cdisc
publish

<tbody>
</tbody>
visible

<tbody>
</tbody>
instock

<tbody>
</tbody>
15Mounted|Mounted5|Mounted9|Motor7Mounted|Mounted5|Mounted9|Motor7blade10|blade11|blade15

<tbody>
</tbody>

I'm usually pretty good at finding similar posts and copying or tweaking code for my needs but I'm not even sure where to start on this one. There will be thousands of products so a VBA script to acheive this would be ideal.

Any assistance would be greatly appreciated.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this:-
NB:- This code will update and remove unwanted rows from your Data.
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Jun36
[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] nRng [COLOR="Navy"]As[/COLOR] Range
[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
    [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
        .Add Dn.Value, Dn
    [COLOR="Navy"]Else[/COLOR]
       [COLOR="Navy"]If[/COLOR] InStr("#" & .Item(Dn.Value).Offset(, 6).Value & "#", "#" & Dn.Offset(, 6).Value & "#") = 0 [COLOR="Navy"]Then[/COLOR]
                .Item(Dn.Value).Offset(, 6).Value = _
                .Item(Dn.Value).Offset(, 6).Value & ", " & Dn.Offset(, 6).Value
        [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]If[/COLOR] InStr("#" & .Item(Dn.Value).Offset(, 7).Value & "#", "#" & Dn.Offset(, 7).Value & "#") = 0 [COLOR="Navy"]Then[/COLOR]
                .Item(Dn.Value).Offset(, 7).Value = _
                .Item(Dn.Value).Offset(, 7).Value & ", " & Dn.Offset(, 7).Value
         [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]If[/COLOR] InStr("#" & .Item(Dn.Value).Offset(, 9).Value & "#", "#" & Dn.Offset(, 9).Value & "#") = 0 [COLOR="Navy"]Then[/COLOR]
             .Item(Dn.Value).Offset(, 9).Value = _
             .Item(Dn.Value).Offset(, 9).Value & ", " & Dn.Offset(, 9).Value
          [COLOR="Navy"]End[/COLOR] If
            [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"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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