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

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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
 
Upvote 0

Forum statistics

Threads
1,217,501
Messages
6,137,013
Members
450,038
Latest member
JackOfBlades

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