Accumulate Amounts based on condition

bobkap

Active Member
Joined
Nov 22, 2009
Messages
313
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have a report I need to run weekly. Typically, there are around 2,000 rows of data. Where a specific cell in the same column have the same data, I want to sum the data in another cell on the same row (vlookup), plus count the number of entries. As an example:

57 Apples
12 Bananas
6 Pears
7 Pears
6 Bananas

How do I use vba to collect and store my total sum AND count of each fruit? OR, should I try to accomplish this using a pivot table?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Can be accomplished with one action employing Power Query. Here is the Mcode

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column2"}, {{"Sum", each List.Sum([Column1]), type number}, {"Count", each Table.RowCount(_), type number}})
in
    #"Grouped Rows"

Book1
ABC
1Column2SumCount
2Apples571
3Bananas182
4Pears132
Sheet2
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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