Find subtotal values in a dynamic range - Formula or VBA

Izzy10

New Member
Joined
Jun 1, 2022
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

This is my first post here on this forum.

Please see the sample set of data below, this data is on a worksheet called Éxpenses'.
It is a report extracted from our database so there are no formulas on this sheet.

Book1
ABCD
1Telephone
201-MayName1Description100
302-MayName2Description200
4Sub total300
5
6Stationery
703-MayName1Description10
804-MayName2Description50
904-MayName3Description45
1004-MayName4Description20
1106-MayName5Description18
12Sub total143
13
14Car
1505-MayName1Description515
1605-MayName2Description1583
1706-MayName3Description200
18Sub total2298
Expenses


I am trying to find a way to capture subtotals for each categories (highlighted yellow),
the subtotal will always be in the same column (D), but the row is dynamic so it will always be different number of rows each time I run this calculation (once a week).
I would like the subtotal to be shown on a separate worksheet called 'Summary'
Cell B2 - Telephone subtotal
Cell B3 - Stationery subtotal
Cell B4 - Car subtotal

It would be great if I could achieve this using a formula.
If a formula is not possible, vba will be fine as well.

Thank you!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Welcome to Mr Excel forum

Maybe something like this

31052022 Testes.xlsm
AB
1CategorySub Total
2Telephone300
3Stationery143
4Car2298
Summary
Cell Formulas
RangeFormula
B2:B4B2=INDEX(INDEX(Expenses!D:D,MATCH(A2,Expenses!A:A,0)):Expenses!D$1000,MATCH("Sub total",INDEX(Expenses!A:A,MATCH(A2,Expenses!A:A,0)):Expenses!A$1000,0))


M.
 
Upvote 0
Thank you so much @Marcelo Branco, it is working great!

I have another question, in relation to this workbook.

In the 'Summary' sheet, there are many other categories in Column A.
For example, if there is a category called 'IT', but this data is not available in the 'Expense' Sheet,
It is now returning '#N/A' in the subtotal cell (column B)

How could the formula be modified so it will show '0' in these case?

Book1
AB
1CategorySub Total
2Telephone300
3Stationery143
4Car2298
5IT#N/A
Summary
Cell Formulas
RangeFormula
B2:B5B2=INDEX(INDEX(Expenses!D:D,MATCH(A2,Expenses!A:A,0)):Expenses!D$1000,MATCH("Sub total",INDEX(Expenses!A:A,MATCH(A2,Expenses!A:A,0)):Expenses!A$1000,0))
 
Upvote 0
How could the formula be modified so it will show '0' in these case?

Try
B2 copied down
=IF(COUNTIF(Expenses!A:A,A2),INDEX(INDEX(Expenses!D:D,MATCH(A2,Expenses!A:A,0)):Expenses!D$1000,MATCH("Sub total",INDEX(Expenses!A:A,MATCH(A2,Expenses!A:A,0)):Expenses!A$1000,0)),0)

M.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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