Macro To Insert Row and Sum

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I wonder if someone could point me in the right direct...

I have a spreadsheet with a table that has details on product sales. The table is sorted by product number, and inlcudes 9 columns, covering such things as invoice number, product code, product description, customer name and customer city. Column H has the sales value in dollars.

What I want to do is to create a macro that will insert a sub-total sales row for each product code. The number of rows for each product will typically vary. For example, the first 6 rows might be for Product A, then the next 3 rows Product B, then the next 10 for Product F, etc.

So the idea is that when I activate the macro, it will start at the top of the table, and, based on the example above, insert a row between Product A and B and put a subtotal in Column H which will be the sum of the 6 rows above. It would then insert a row between Product B and C covering the 3 rows for product B, etc.

The Product Code is in Column B. The whole table data area, excluding titles, has the range name "Sales_Data" - not sure if this is useful.

Thanks,

MikeG
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
MikeG,
I think Data-->Subtotals command should do exatly what you want.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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