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
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,118,908
Messages
5,574,965
Members
412,630
Latest member
Eireangel
Top