sum up total quantity

freezefiz

Board Regular
Joined
May 21, 2008
Messages
101
I've found this great code which deletes duplicated rows.
And it'll be great if i could get some help in modifying it so as to achieve my desired output.

Code:
Dim lngTMP As Long, iRows As Long
    On Error GoTo Fin
    Application.ScreenUpdating = False
    iRows = Cells(Cells.Rows.Count, 2).End(xlUp).Row
    For lngTMP = iRows To 6 Step -1
        If WorksheetFunction.CountIf(Columns(2), Cells(lngTMP, 2)) > 1 Then
 Rows(lngTMP).Delete
        End If
 Next lngTMP
Fin:
    Application.ScreenUpdating = True

Before combining :
protoV6.xls
ABCD
1PrepareDate:6/18/2008
2Day:Wednesday
3DeliverDate:
4ProductIDProductUomQty
5TDG-**002TunaCheesePizzaBar(KG)KG30
6RFG-**588ThaiChickenFriedRice(KG)KG30
7RFG-**502ClubSandwich(PKT)PKT3
8RFG-**501RoastMexicanChicken(PKT)PKT15
9RFG-**501RoastMexicanChicken(pcs)pcs12
10TDG-**002TunaCheesePizzaBar(pcs)pcs15
11RFG-**501RoastMexicanChicken(KG)KG10
12TDG-**002TunaCheesePizzaBar(KG)KG30
13RFG-**588ThaiChickenFriedRice(KG)KG30
14RFG-**502ClubSandwich(PKT)PKT3
15RFG-**501RoastMexicanChicken(PKT)PKT15
16RFG-**501RoastMexicanChicken(pcs)pcs12
17TDG-**002TunaCheesePizzaBar(pcs)pcs15
18RFG-**501RoastMexicanChicken(KG)KG10
19TDG-**002TunaCheesePizzaBar(KG)KG30
20RFG-**588ThaiChickenFriedRice(KG)KG30
21RFG-**502ClubSandwich(PKT)PKT3
22RFG-**501RoastMexicanChicken(PKT)PKT15
23RFG-**501RoastMexicanChicken(pcs)pcs12
24TDG-**002TunaCheesePizzaBar(pcs)pcs15
25RFG-**501RoastMexicanChicken(KG)KG10
GrandTotal


As shown below, the duplicated rows are deleted, and unfortunately this also means that the quantity for that row is also deleted.

But i would like is to sum up all the qty for that product & so only the total will be displayed.

After combining :
protoV6.xls
ABCD
1PrepareDate:6/18/2008
2Day:Wednesday
3DeliverDate:
4ProductIDProductUomQty
5TDG-**002TunaCheesePizzaBar(KG)KG30
6RFG-**588ThaiChickenFriedRice(KG)KG30
7RFG-**502ClubSandwich(PKT)PKT3
8RFG-**501RoastMexicanChicken(PKT)PKT15
9RFG-**501RoastMexicanChicken(pcs)pcs12
10TDG-**002TunaCheesePizzaBar(pcs)pcs15
11RFG-**501RoastMexicanChicken(KG)KG10
GrandTotal


Pls Advise.
Thanks.
 
Ah. Much Clearer now.
Jindon: I tested your code, it didn't add up the quantity value.
I could be wrong, but it seems that she wants to add up the quantity as well.
I have written the code according to the sample and result from OP's 1st post.
Add up?
Rich (BB code):
Sub test()
Dim a, i As Long, ii As Long, b(), n As Long, z As String
With Range("a5", Range("a" & Rows.Count).End(xlUp)).Resize(,4)
    a = .Value
    ReDim b(1 To UBound(a,1), 1 To UBound(a,2))
    With CreateObject("Scripting.Dictionary")
        .CompareMode = vbTextCompare
        For i = 1 To UBound(a,1)
            z = a(i,1) & ";" & a(i,2)
            If Not .exists(z) Then
                n = n + 1 : .add z, n
                For ii = 1 To UBound(a,2) : b(n,ii) = a(i,ii) : Next
            Else
                b(.item(z), 4) = b(.item(z), 4) + a(i,4)
            End If
        Next
    End With
    .Value = b
End With
End Sub
 
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
Jindon i've banned him at Excel Forum, it's disrespectful and an abuse of the free help we give thats why i didn't reply to his follow up question about the uom in page 1!
 
Upvote 0
Jindon i've banned him at Excel Forum, it's disrespectful and an abuse of the free help we give thats why i didn't reply to his follow up question about the uom in page 1!

Yes, this guy is using 3 different user names as far as I know.

"Pukka", "Guanjin, Peter" and "freezefiz"
 
Upvote 0
Pukka, if you have more than 1 username, then I am sorry to say that you are a loser.

I would only suggest the Administrators or Moderators to track the IPs of all the members as they would help extensively to limit the number of IDs created by a member on the Board. It is not a complete solution but it can help to an extent according to my understanding.
 
Upvote 0
Guys.. i'm so sorry for this confusion.

"pukka, guanjin" & me is a different person.
i truly regret for the discomfort that it may cause to guanjin and other fellow excel experts.

The questions we posted may be similar, and that's because we're working on the same project.

We interpret the questions differently as we think that different experts have different ways of understanding the questions.

I'm so sorry for any inconvenience cause.

and I didn't think that it'd be a major issue.

But i truly appreciate all the help that i've gotten from the fellow experts here. A huge thanks to all who've helped me through the project development.

And sorry guanjin for putting you in such situation.
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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