how to automatically sum and merge rows based on same value in column?

chezchez

New Member
Joined
Nov 30, 2012
Messages
2
hello, can anyone help me perform the following calculation in excel please?

I have a long list of items and their quantities, example:
[TABLE="width: 128"]
<tbody>[TR]
[TD="width: 64, align: right"]101001[/TD]
[TD="width: 64, align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]101001[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101001[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]101001[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]101002[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101002[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]101003[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101004[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101005[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]1[/TD]
[/TR]
</tbody>[/TABLE]

now i would like to merge all the rows with the same value in column A and add up the corresponding values in column B to return the following:


[TABLE="width: 128"]
<tbody>[TR]
[TD="width: 64, align: right"]101001[/TD]
[TD="width: 64, align: right"]10[/TD]
[/TR]
[TR]
[TD="align: right"]101002[/TD]
[TD="align: right"]7[/TD]
[/TR]
[TR]
[TD="align: right"]101003[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101004[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101005[/TD]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]101050[/TD]
[TD="align: right"]13[/TD]
[/TR]
</tbody>[/TABLE]

I am guessing I have to run a macro, but I have no idea how to do that... any help would be much appreciated!
thanks, chez
 
Sorry tried to post image didnt work. Data Headers Start at B4


[TABLE="width: 937"]
<tbody>[TR]
[TD="colspan: 3"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Quote #[/TD]
[TD]13534[/TD]
[/TR]
[TR]
[TD]FINISHED
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD] B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[TD]J[/TD]
[TD]K[/TD]
[TD]L[/TD]
[TD]M[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Code[/TD]
[TD]GAP[/TD]
[TD]Wages[/TD]
[TD] Rate[/TD]
[TD] Billed[/TD]
[TD]Est[/TD]
[TD]Cost[/TD]
[TD]n[/TD]
[TD]Rate[/TD]
[TD]cost[/TD]
[TD]Fee[/TD]
[TD]Fee2[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CA 8810[/TD]
[TD] $ 175,000[/TD]
[TD] $ 175,000[/TD]
[TD]2.58%[/TD]
[TD] $ 2,375[/TD]
[TD] $ 1,540[/TD]
[TD] $ 308[/TD]
[TD]0.00%[/TD]
[TD]1.20%[/TD]
[TD] $ 1,200[/TD]
[TD]3.78%[/TD]
[TD] $ 3,575[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CA 9008[/TD]
[TD] $ 960,000[/TD]
[TD] $ 960,000[/TD]
[TD]49.04%[/TD]
[TD] $ 194,452[/TD]
[TD] $ 160,416[/TD]
[TD] $ 32,083[/TD]
[TD]0.00%[/TD]
[TD]1.20%[/TD]
[TD] $ 3,000[/TD]
[TD]50.24%[/TD]
[TD] $ 197,452[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]CO 9014[/TD]
[TD] $ 795,000[/TD]
[TD] $ 795,000[/TD]
[TD]6.60%[/TD]
[TD] $ 24,899[/TD]
[TD] $ 28,382[/TD]
[TD] $ 5,676[/TD]
[TD]0.00%[/TD]
[TD]1.20%[/TD]
[TD] $ 1,800[/TD]
[TD]7.80%[/TD]
[TD] $ 26,699[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Totals[/TD]
[TD] $ 1,930,000[/TD]
[TD] $ 1,930,000[/TD]
[TD][/TD]
[TD] $ 221,726[/TD]
[TD] $ 190,338[/TD]
[TD] $ 38,068[/TD]
[TD][/TD]
[TD][/TD]
[TD] $ 6,000[/TD]
[TD][/TD]
[TD] $ 227,726[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
----------------------------------------------------------------------------------------------------------------------------------
ORIGINAL

[TABLE="width: 891"]
<tbody>[TR]
[TD]CA 9008[/TD]
[TD] $ 250,000[/TD]
[TD] $ 250,000[/TD]
[TD]33.42%[/TD]
[TD] $ 83,550[/TD]
[TD] $ 41,775[/TD]
[TD] $ 8,355[/TD]
[TD]0.00%[/TD]
[TD]1.20%[/TD]
[TD] $ 3,000[/TD]
[TD]34.62%[/TD]
[TD] $ 86,550[/TD]
[/TR]
[TR]
[TD]CA 8810[/TD]
[TD] $ 100,000[/TD]
[TD] $ 100,000[/TD]
[TD]1.76%[/TD]
[TD] $ 1,760[/TD]
[TD] $ 880[/TD]
[TD] $ 176[/TD]
[TD]0.00%[/TD]
[TD]1.20%[/TD]
[TD] $ 1,200[/TD]
[TD]2.96%[/TD]
[TD] $ 2,960[/TD]
[/TR]
[TR]
[TD]CO 9014[/TD]
[TD] $ 150,000[/TD]
[TD] $ 150,000[/TD]
[TD]3.57%[/TD]
[TD] $ 5,355[/TD]
[TD] $ 5,355[/TD]
[TD] $ 1,071[/TD]
[TD]0.00%[/TD]
[TD]1.20%[/TD]
[TD] $ 1,800[/TD]
[TD]4.77%[/TD]
[TD] $ 7,155[/TD]
[/TR]
[TR]
[TD]CA 9008[/TD]
[TD] $ 710,000[/TD]
[TD] $ 710,000[/TD]
[TD]15.62%[/TD]
[TD] $ 110,902[/TD]
[TD] $ 118,641[/TD]
[TD] $ 23,728[/TD]
[TD]0.00%[/TD]
[TD]0.00%[/TD]
[TD] $ -[/TD]
[TD]15.62%[/TD]
[TD] $ 110,902[/TD]
[/TR]
[TR]
[TD]CA 8810[/TD]
[TD] $ 75,000[/TD]
[TD] $ 75,000[/TD]
[TD]0.82%[/TD]
[TD] $ 615[/TD]
[TD] $ 660[/TD]
[TD] $ 132[/TD]
[TD]0.00%[/TD]
[TD]0.00%[/TD]
[TD] $ -[/TD]
[TD]0.82%[/TD]
[TD] $ 615[/TD]
[/TR]
[TR]
[TD]CO 9014[/TD]
[TD] $ 645,000[/TD]
[TD] $ 645,000[/TD]
[TD]3.03%[/TD]
[TD] $ 19,544[/TD]
[TD] $ 23,027[/TD]
[TD] $ 4,605[/TD]
[TD]0.00%[/TD]
[TD]0.00%[/TD]
[TD] $ -[/TD]
[TD]3.03%[/TD]
[TD] $ 19,544[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this:-
Nb:- Your Dollar formatted numbers appear on my sheet as text, so I removed the dollars signs and reformatted as dollars.
Code:
[COLOR="Navy"]Sub[/COLOR] MG15Apr38
[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] lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] col [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range, Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("B4"), Range("B" & 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"]For[/COLOR] n = 1 To 11
           .Item(Dn.Value).Offset(, n).Value = _
           .Item(Dn.Value).Offset(, n).Value + Dn.Offset(, n).Value
        [COLOR="Navy"]Next[/COLOR] n
           [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] With
lst = Range("B" & Rows.Count).End(xlUp).Row
    Range("B" & lst + 1).Value = "Totals"
    col = Array(1, 2, 4, 5, 6, 9, 11)
    [COLOR="Navy"]For[/COLOR] n = 0 To UBound(col)
        Range("B" & lst + 1).Offset(, col(n)) = Application.Sum(Range("B4").Offset(, col(n)).Resize(lst - 3))
        Range("B" & lst + 1).Offset(, col(n)).NumberFormat = "[$$-409]#,##0"
    [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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