Subtotals

mhaidar81

New Member
Joined
Dec 9, 2017
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to figure out if there's a way to use VBA to find subtotals based on two criteria. The data is already sorted by these two criteria (line number and department number) and I'd like to be able to draw a bottom border across the cells and put the subtotal on the last cell that this data appears on.
bA6uEb
This data is dynamic.

Line Dept Sales Amount Total
13 Dept 1 Cookies 10
14 Dept 1 Cookies 10 $20
05 Dept 2 Beer 30 $30
06 Dept 3 Cookies 10
07 Dept 3 Cookies 10 $20
01 Dept 3 Wine 40
02 Dept 3 Wine 40
03 Dept 3 Wine 40 $120
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi mhaidar81,

Welcome to the MrExcel Forum.

I am looking at your sample data and I cannot figure out what the criteria for the subtotals is. It cannot be the Department because you two different totals for Dept 3, and it cannot be the item because you have two different totals for Cookies. Is it a combination of Department AND item.
 
Upvote 0
Hi igold,

The subtotal is for groups that are identical in department and sales. For all Dept 1 and Cookies, find total and put it on the last line of that grouping while applying bottom border. For all Dept 3 and Wine, find the total and place on last line of that grouping while applying bottom border. Does that make sense?
 
Upvote 0
I was able to get the subtotal on the lines that I want, but how can I have the macro draw a bottom border across an entire row if the column is not blank?

For example, if cell G6 is not blank, apply bottom border to A6:G6. Move to the next non-blank cell and apply a bottom border until the entire range is checked.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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