Data Sort with two conditions

M9791

New Member
Joined
Sep 29, 2018
Messages
2
Hello,
I would like to create a macro to help me out with some manual data processing that I do at work.
I export the data into excel from a website and it is always set up with the same columns.
Column A contains a 5 character identifier. (Ex. A1234). There are typically multiples rows for each identifier.
For each row, column B contains either X or Y.
Column C contains a number.

What I want the macro to do is give me the sum for x and the sum for y of column “c” for each column “a” identifier.

Any help is appreciated.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
Code:
Sub SumValues()
   Dim Ary As Variant, Nary As Variant
   Dim i As Long
   Dim v As String
   
   Ary = Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(, 3)).value2
   With CreateObject("scripting.dictionary")
      For i = 1 To UBound(Ary)
         v = Ary(i, 1) & "|" & Ary(i, 2)
         .Item(v) = .Item(v) + Ary(i, 3)
      Next i
      ReDim Nary(1 To .Count, 1 To 3)
      For i = 0 To .Count - 1
         Nary(i + 1, 1) = Split(.keys()(i), "|")(0)
         Nary(i + 1, 2) = Split(.keys()(i), "|")(1)
         Nary(i + 1, 3) = .items()(i)
      Next i
      Range("D1").Resize(.Count, 3) = Nary
   End With
End Sub
 
Upvote 0
Thanks for the quick reply. I am gonna give this code a try later today.
Just so I understand it, could you explain what each for loop is doing? Also, is the line defining ary just defining the data set?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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