VBA to summarize data?

Holley

Board Regular
Joined
Dec 11, 2019
Messages
120
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello all!

I am looking for a way to summarize numerous rows of data. It could possibly exceed 100k rows. For example, column A is a reference #. I need to count how many times this row is listed. Column H is an amount and I need for it to subtotal each reference #. For example Row A is 1234 and there are 100 instance that total $50000. I need this to happen at each change in column A and, if possible, copy the data to a new spreadsheet.
Would this be possible with VBA?

Thanks in advance!!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I don't think you need VBA to do it.
Sounds like something you should be able to do with Pivot Tables, Subtotals, or Power Query.
If it was me, with that much data I would dump it into a relational database program like Microsoft Access where grouping, counting, totalling, and reporting on data becomes much easier, especially with large amounts of data. But you should be able to do similar functions in Power Query in Excel.
 
Upvote 0
from your description it I think your data is sorted by the reference number. You stated that "this needs to happen at each change in Column A" (that suggests to me that your data is sorted).
If it is sorted then the VBA code to total at each change in the reference number is pretty easy.
 
Upvote 0
If it is sorted then the VBA code to total at each change in the reference number is pretty easy.
Isn't that what inserting Subtotals already does?
No sense in recreating the wheel...
 
Upvote 0
Isn't that what inserting Subtotals already does?
No sense in recreating the wheel...
True, but I only need the summarized data and I was hoping VBA may accomplish this
 
Upvote 0
from your description it I think your data is sorted by the reference number. You stated that "this needs to happen at each change in Column A" (that suggests to me that your data is sorted).
If it is sorted then the VBA code to total at each change in the reference number is pretty easy.
Yes, this is sorted. I have tried using Subtotals, but I need these on the same row, not subtotal in one row and count on another if possible.
 
Upvote 0
I think it will probably be necessary for you to show us some sample data and your expected output, as with VBA, so much is dependent on your actual data layout.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
I think it will probably be necessary for you to show us some sample data and your expected output, as with VBA, so much is dependent on your actual data layout.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
Totally understandable! This is an example of how the data is in the spreadsheet
Sample 1.xlsx
ABCDEFGHI
1V#VnameC#CnamequeueI DateI# I$ Ddate
20234Ralph Lauren1234567Susie Jones1A7/6/2023123$ 121.008/5/2023
30234Ralph Lauren1234567Susie Jones1A7/7/2023124$ 1,258.558/6/2023
40234Ralph Lauren1234567Susie Jones1A7/7/2023125$ 578.588/6/2023
51234Equestrian 1234567Susie Jones1A6/1/2023456$ 878.887/1/2023
61234Equestrian 1234567Susie Jones1A6/5/2023457$ 4,875.007/5/2023
71234Equestrian 1234567Susie Jones1A6/15/2023458$ 78.007/15/2023
81234Equestrian 1234567Susie Jones1A7/1/2023459$ 81.007/31/2023
95678MAC1234567Susie Jones1A8/1/202312$ 108.008/31/2023
105678MAC1234567Susie Jones1A8/1/202313$ 126.008/31/2023
Sheet1


And this is how I need the data to be summarized (preferably in a new spreadsheet, but new tab if not possible)
Desired Output.xlsx
ABCDEFG
1V#VnameC#Cnamequeue# of I Tally
20234Ralph Lauen1234567Susie Jones1A3$ 1,958.13
31234Equestrian1234567Susie Jones1A4$ 5,912.88
45678MAC1234567Susie Jones1A2$ 234.00
5Grand Total9$ 8,105.01
Sheet1
Cell Formulas
RangeFormula
F5:G5F5=SUM(F2:F4)
 
Upvote 0
For your Office version, you have listed both 365 and 2016.
Which one are you currently using?
365 has a bunch of new functions that 2016 does not.
 
Upvote 0
Power Query Solution

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"V#", Int64.Type}, {"Vname", type text}, {"C#", Int64.Type}, {"Cname", type text}, {"queue", type text}, {"I Date", type date}, {"I#", Int64.Type}, {" I$ ", type number}, {"Ddate", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"V#", "Vname", "C#", "Cname", "queue"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"Sum", each List.Sum([#" I$ "]), type nullable number}})
in
    #"Grouped Rows"
 
Upvote 0
Solution

Forum statistics

Threads
1,215,098
Messages
6,123,082
Members
449,094
Latest member
mystic19

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