Having Trouble Tackling a larger formula: need to return multiple values based on multiple criteria

Meth0dman27

New Member
Joined
May 6, 2018
Messages
5
Hi All

I have a fairly tricky situation that I'm trying to solve that I'm not entirely sure is possible. I'll give a brief explanation below but if anyone wants to attempt it I can give a more detailed examples of the data.

I am trying to create a list that generates the items I need, in Sheet3, using data that is dispersed through sheets 1 and 2. Essentially I need a formula that will be able to do a "vlookup" based on multiple criteria but also be able to return multiple criteria. Further explanation below:

Sheet1 contains 3 pieces of relevant info: Recipe Code, Area, Recipe Type. In this instance, recipe type refers to protein, starch, veg, sauce, protein (halal). I am specifically looking for only non protein items, so I started my if stated with: =if(not(or(q2="Protein",q2="Protein (Halal)), ...... , .......)

Sheet2 Contains the breakdown of the recipe codes and shows the ingredients used via ingredient codes. Ingredient codes are what I'm trying to populated in sheet3. In this sheet, Column A is recipe code from sheet1, column B is ingredient code. Because each recipe has multiple ingredients it looks as such:

RecipeIngredient CodeIngredient
2VE0001564Spinach
2VE0001215Mush
2VE0001669Butter
2VE0001293Oil
2VE0001584Salt

<tbody>
</tbody>

Because the "2VE0001" is on multiple lines a regular vlookup doesn't work as I may need to return multiple values

Sheet3 is where the data needs to be populated. This is also where another criteria I need to use comes into play. In this sheet I divide those ingredients further by "Area". So for example Area "Kit1" might have codes 2VE0001,2VE0002,2VE0003, and those 3 recipes might have 10 ingredients. I would need all 10 of those ingredients based on the area. Below is an example to give you an idea what I mean.

AreaIngredient NumberQuantity
KIT156410
KIT121520
KIT164330
KIT224840
KIT264550
KIT221560

<tbody>
</tbody>

So essentially the info I need is column B on the last table, which are obtained from sheet 2 using criteria from sheets 1 & 3. I realize this is probably very confusing but any help you might have would be very much appreciated!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Method,

Can you post examples of the data from Sheet 1 and confirm what is the criteria you will choose from both requirements?

I assume you will choose e.g. "2VE0001", and Kit1 as criteria?
 
Upvote 0
Hi!

Thanks for the reply.

Here's a condensed version of Sheet1:

ABC
1RecipeAreaRecipe Type
22VE0001Kit1Veg
32VE0002Kit2Veg
42CX0001Kit1Protein
52HL0001Kit2Protein (Halal)

<tbody>
</tbody>

To answer your question, yes I would need to use Kit1 and 2VE0001 as criteria. from here I'm looking for anything in column A that is not either protein or protein (halal). So to filter those out I was thinking of start an IF statement like below

Code:
[COLOR=#574123]not(or(q2="Protein",q2="Protein (Halal))[/COLOR]

Once I have those recipe codes, I need to then reference sheet 2 to get my ingredient codes.

This would be sheet2:

Recipe CodeInredient CodeIngredient Code
2VE0001123Mushrooms
2VE0001456Spinach
2VE0001789Garlic
2VE0002321Carrots
2VE0002654Onion
2VE0002987Celery

<tbody>
</tbody>

Finally, I would then need to have them placed into sheet 3 like this:

AreaIngredient
Kit1123
Kit1456
Kit1789
Kit2321
Kit2654
Kit3987

<tbody>
</tbody>
 
Upvote 0
Hi Method,

Maybe you could use this. Sheet 2 has a helper Column to bring the Area code into Sheet 2.

Column D counts the criteria for the array formulas.

Increase the ranges to suit your data. You will also need to increase the number of OR conditions in this line to match your "Not Proteins count"

SMALL(IF(OR(Sheet2!$A$2:$A$7=Sheet3!$D$8,Sheet2!$A$2:$A$7=Sheet3!$D$9)


Book1
ABCD
1Recipe CodeIngredient CodeIngredientHelper
22VE0001123MushroomsKit1
32VE0001456SpinachKit1
42VE0001789GarlicKit1
52VE0002321CarrotsKit2
62VE0002654OnionKit2
72VE0002987CeleryKit2
Sheet2
Cell Formulas
RangeFormula
D2=IF(C2="","",INDEX(Sheet1!$B$2:$B$5,MATCH(Sheet2!A2,Sheet1!$A$2:$A$5,0)))



Book1
ABCDE
1AreaIngredientSheet2 Recipes Count
2Kit11236
3Kit1456
4Kit1789Not Proteins Count
5Kit23212
6Kit2654
7Kit2987Recipes Non-ProteinsCount
82VE00013
92VE00023
Sheet3
Cell Formulas
RangeFormula
D2=SUM(E8:E9)
D5=COUNTA(Sheet1!$C$2:$C$5)-(COUNTIF(Sheet1!$C$2:$C$5,"Protein")+COUNTIF(Sheet1!$C$2:$C$5,"Protein (Halal)"))
D8{=IF(ROWS(Sheet3!$D$8:D8)>$D$5,"",INDEX(Sheet1!$A$2:$A$5,SMALL(IF(NOT(Sheet1!$C$2:$C$5="Protein"),IF(NOT(Sheet1!$C$2:$C$5="Protein (Halal)"),ROW(Sheet1!$C$2:$C$5)-ROW(Sheet1!$C$2)+1)),ROWS(Sheet3!$D$8:D8))))}
E8=COUNTIF(Sheet2!$A$2:$A$7,Sheet3!$D8)
A2{=IF(ROWS($A$2:A2)>$D$2,"",INDEX(Sheet2!$D$2:$D$7,SMALL(IF(OR(Sheet2!$A$2:$A$7=Sheet3!$D$8,Sheet2!$A$2:$A$7=Sheet3!$D$9),ROW(Sheet2!$A$2:$A$7)-ROW(Sheet2!$A$2)+1),ROWS($A$2:A2))))}
B2{=IF(ROWS($A$2:A2)>$D$2,"",INDEX(Sheet2!$B$2:$B$7,SMALL(IF(OR(Sheet2!$A$2:$A$7=Sheet3!$D$8,Sheet2!$A$2:$A$7=Sheet3!$D$9),ROW(Sheet2!$A$2:$A$7)-ROW(Sheet2!$A$2)+1),ROWS($A$2:A2))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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