Flexible totals based on lists

crocco

Board Regular
Joined
Jan 28, 2010
Messages
142
I have two worksheets one called ‘products’ and one called ‘totals’.

‘Products’ has the following column headings starting in the range A1 to A5: ‘Sales’, ‘apples’, ‘oranges’, ‘pears’, ‘bananas’. Cells B2 to B5 contain numeric data. I would like a formula in cell A2 that totals all cells in row 2 that have a heading (row 1) listed in the ‘totals’ sheet.

For example if the ‘totals’ sheet cell
A1 contains ‘Sales’ heading, A2 contains ‘apples’ and A3 contains ‘Pears’; then the formula in A2 would match it’s heading (‘sales’) to the corresponding column in the ‘totals’ sheet and then add across only the cells in row 2 on the ‘Products’ sheet which have headings matching those listed under ‘sales’ in the ‘totals’ sheet ie only total the numeric data for ‘apples’ and ‘pears’.

I want this formula to be as flexible as possible to handle as many headings as can be listed across row 1 on the ‘totals’ sheet with as many items to total listed underneath.

For example if on the ‘totals’ sheet I made another heading called ‘yellow fruit’ in cell B1 and put ‘bananas’ in cell B2, I could then on the ‘products’ sheet insert a column headed ‘yellow fruit’ next to the column headed ‘sales’, drag across the formula and it would know to only total ‘bananas’ data.

Hope that makes sense!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe something like this...

Let's say you have

totals sheet
A
B
1
Sales​
2
apples​
3
Pears​

<tbody>
</tbody>


products
A
B
C
D
E
1
Sales​
apples
oranges​
pears​
bananas​
2
22​
10
11
12​
13​

<tbody>
</tbody>


Formula in A2
=SUMPRODUCT(SUMIF($B$1:$Z$1,INDEX(totals!$A$2:$Z$10,0,MATCH(A$1,totals!$A$1:$Z$1,0)),$B$2:$Z$2))

Then you add another heading in totals

A
B
C
1
Sales​
Yellow fruit​
2
apples
bananas​
3
Pears

<tbody>
</tbody>


In products insert a new column and drag the formula to B2

A
B
C
D
E
F
1
Sales​
Yellow fruit​
apples​
oranges​
pears​
bananas​
2
22​
13​
10​
11​
12​
13​

<tbody>
</tbody>


Hope this helps

M.
 
Upvote 0
Thanks so much! How do I get tables to appear in my future posts like you did in your reply?
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,675
Members
449,116
Latest member
HypnoFant

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