SUM function with LOOKUP to a Dynamic List

masud8956

Board Regular
Joined
Oct 22, 2016
Messages
163
Office Version
  1. 2016
  2. 2011
  3. 2007
Platform
  1. Windows
Hi all,

I am having some trouble summing up some data from the dynamic range B2:C15. All the fruit names that populate $B$2:$B$15 belong to to either of the 4 groups. These 4 groups are also dynamic lists.

They are:

Group1: Range $E$3:$E$15,
Group2: Range $F$3:$F$15,
Group3: Range $G$3:$G$15 and
Group4: Range $H$3:$H$15,

A1B1C1D1E1F1G1H1
A2FRUITPRICEGROUP1GROUP2GROUP3GROUP4
A3Apple50AppleBananaGrapeDate
A4Lemon60OrangeMangoPeachLemon
A5Cherry70Avocado
A6Coconut80Cherry
A7Coconut
A8
A9
A10
A11
A12
A13
A14
A15

<tbody>
</tbody>

I want to sum up the values from B2:C15 in the following style:

Column C should show types of fruit and Column D should sum up the prices group wise.

A15B15C15D15
A16GROUPFRUITPRICE
A17GROUP1Apple50
A18GROUP2--
A19GROUP3Cherry, Coconut150
A20GROUP4Lemon60

<tbody>
</tbody>

Can anyone please help with a suitable Formula?

Thanks in advance!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi @XOR LX again,

I am sorry I did not see this yesterday.

The formula works fine to lists with simple define name technique.

To keep the lists dynamic I am udefining names with following formula:

Code:
=OFFSET('Sheet1'!$E$3,0,0,0,COUNTA('Sheet1'!$E$3:$E$15))

.....and now the formula returns zero value.

What did I do wrong?
 
Upvote 0
INDIRECT doesn't work with dynamically-defined Named Ranges.

There are workarounds available, though can I first ask if you really need to make those lists dynamic?

Regards
 
Upvote 0
Yes sir.

I need those lists to be dynamic.

Thanks!
 
Upvote 0
For a start, I prefer to avoid the volatile OFFSET when defining dynamic ranges. I would use:

=Sheet1!$E$3:INDEX(Sheet1!$E$3:$E$15,MATCH("zzz",Sheet1!$E$3:$E$15))

etc.

You then have two options:

Option 1

Remove the INDIRECT references altogether (thus removing all volatility).

=SUMPRODUCT(SUMIF(B$3:B$6,GROUP_1,C$3:C$6))

etc.

Obviously this requires you to manually hard-code the group names within each formula, though has the advantage that it removes the volatile INDIRECT.

Option 2

Use the EVALUATE function, viz:

With the active cell somewhere in row 17, go to Name Manager and define:

Name: Formula1
Refers to: =EVALUATE(SUBSTITUTE(Sheet1!$B17," ","_"))

Exit Name Manager.

The formula in D17 then becomes:

=SUMPRODUCT(SUMIF(B$3:B$6,Formula1,C$3:C$6))

and copied down.

The only slight drawback to this approach is that, although you have not entered any VBA 'proper', the use of EVALUATE within Name Manager still requires that your workbook be saved as macro-enabled.

Regards
 
Upvote 0
You then have two options:........

I am using Option 1. Working perfectly.

Option 2 is equally good as my workbook is already macro-enabled.
Thank you very much for taking the time and explaining 2 beautiful options! Learned a lot from you. (y)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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