Summing up qty in similar rows

Rakesh_Parekh

New Member
Joined
Jun 1, 2005
Messages
27
Hi,

My questions are:


1. How to select rows only with "Red" models
2. How to add qty of all similar models into one row and remove rest
For example qty of all "Red" models to be combined in only one row of "Red"


Model Qty
=====================
Red 10
Green 08
Blue 12
Red 05
Red 14
Organge 11
Green 12
Red 09
Green 15

I want the Macro to do is


Model Qty
=====================
Red 38
Green 35
Blue 12
Organge 11


Thanks,
Rakesh
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
try
Code:
Sub test()
Dim dic As Object, x, y, r As Range
Set dic = CreateObject("scripting.dictionary")
For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
    If Not IsEmpty(r) Then
        If Not dic.exists(r.Value) Then
            dic.Add r.Value, r.Offset(, 1).Value
        Else
            dic(r.Value) = dic(r.Value) + r.Offset(, 1).Value
        End If
    End If
Next
x = dic.keys: y = dic.items
Range("a1").CurrentRegion.ClearContents
With Range("a1")
    .Resize(dic.Count) = Application.Transpose(x)
    .Offset(, 1).Resize(dic.Count) = Application.Transpose(y)
End With
Set dic = Nothing: Erase x, y
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,497
Messages
5,832,050
Members
430,108
Latest member
RAZGRIZ

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
Top