Add values from duplicate rows and delete duplicate

jane204

New Member
Joined
Nov 18, 2016
Messages
2
I have the below values and I want to create a macro to add the duplicates and delete it.
Apple=260

<tbody>
</tbody>
Orange=3

<tbody>
</tbody>
Banana=246

<tbody>
</tbody>
Apple=43

<tbody>
</tbody>
Mango=93

<tbody>
</tbody>
Banana=4

<tbody>
</tbody>
Melon=260

<tbody>
</tbody>
Grape=209

<tbody>
</tbody>

<tbody>
</tbody>















I want the result to combine the apples and banana which has duplicate values and give the total number of apples and bananas. Like below.
Apple=303

<tbody>
</tbody>
Orange=3

<tbody>
</tbody>
Banana=250

<tbody>
</tbody>
Mango=93

<tbody>
</tbody>
Melon=260

<tbody>
</tbody>
Grape=209

<tbody>
</tbody>

<tbody>
</tbody>

Thanks!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this:-
NB:- this code will alter the data in column "A"
Code:
[COLOR="Navy"]Sub[/COLOR] MG18Nov38
[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] Q [COLOR="Navy"]As[/COLOR] Variant, Sp [COLOR="Navy"]As[/COLOR] Variant, nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), 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
    Sp = Split(Dn.Value, "=")
    [COLOR="Navy"]If[/COLOR] Not .Exists(Sp(0)) [COLOR="Navy"]Then[/COLOR]
        .Add Sp(0), Array(Dn, Sp(1))
    [COLOR="Navy"]Else[/COLOR]
        Q = .Item(Sp(0))
        Q(1) = Q(1) + CLng(Sp(1))
        Q(0).Value = Sp(0) & "=" & Q(1)
        .Item(Sp(0)) = Q
       [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = Dn Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn)
   [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,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

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