Subtotals

mhaidar81

New Member
Joined
Dec 9, 2017
Messages
17
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.
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
 

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,447
Office Version
365, 2010
Platform
Windows
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.
 

mhaidar81

New Member
Joined
Dec 9, 2017
Messages
17
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?
 

mhaidar81

New Member
Joined
Dec 9, 2017
Messages
17
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.
 

Forum statistics

Threads
1,081,676
Messages
5,360,441
Members
400,586
Latest member
Minty

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top