Nested VLOOKUP Alternative

Keeper4826

New Member
Joined
Nov 6, 2006
Messages
47
On my main sheet, I have a row with two drop down lists. In column B, you select a food category. In column C, you select a specific food item based on the food category selected. The remaining columns to the right of that are for the macro nutrients of the selected food item (carbs, sugar, protein, etc.). There is a one sheet for each food category, each with a table listing out the food items in that category and their individual macro data. There are a total of 7 sheets for the various categories. An additional sheet has been created with a table which correlates food category to corresponding table. For example, the "Fruit" category is on the Fruits sheet, which has Table3. My goal to populate the macro nutrient data of a select food item on the main sheet, pulling that data from the appropriate table based on the food category select.

The first step was to create a VLOOKUP formula based on the food item. I got that to work just fine.
=VLOOKUP(C3,Table4,3,FALSE) 'C3 is the individual item to be search for, Table4 is the table that matches the category of the item selected.

My challenge now is - how do I determine which table is appropriate for the search? My example is hardcoded. What I really need is a nested VLOOKUP based on the data in B3, which would return the appropriate Table value based on my category/table reference sheet.
=VLOOKUP(C3,(VLOOKUP(B3,Table8,2,FALSE)),3,FALSE) 'Searching able8 would return the proper table for the category selected in B3.

This appears to be an invalid formula, as nesting VLOOKUPs is not allowed. How do I solve this issue?

Once I crack this nut, I'd like to know if it's possible to return multiple values based on the search results. This would allow me to input one function in a single cell, but populate five cells (for the various macro data).
 
Couldn't you just use INDIRECT in the first place?

Code:
=VLOOKUP(C3,INDIRECT(VLOOKUP(B3,Table8,2,FALSE)),3,FALSE)

WBD
 
Upvote 0

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
Couldn't you just use INDIRECT in the first place?

Code:
=VLOOKUP(C3,INDIRECT(VLOOKUP(B3,Table8,2,FALSE)),3,FALSE)

WBD

I was thinking that. If the sheet name is the same as the category and theres a different sheet for each one then maybe something like this:

=VLOOKUP($C3,INDIRECT("'"&$B3&"'!A:G"),COLUMNS($A$1:C1),0)

Would negate the need for the lookup table of tables.
 
Upvote 0
I think the INDIRECT formula would be easier:


ABCDEFGHI
Item
Egg (large)
9
Total

<tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]Meal[/TD]
[TD="align: center"]Category[/TD]

[TD="align: center"]Qty[/TD]
[TD="align: center"]Carbs[/TD]
[TD="align: center"]Fat[/TD]
[TD="align: center"]Protein[/TD]
[TD="align: center"]Sugar[/TD]
[TD="align: center"]Calories[/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]MONDAY[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]Breakfast[/TD]
[TD="align: center"]Meats_Eggs_Nuts[/TD]

[TD="align: right"][/TD]
[TD="align: right"]0.38g[/TD]
[TD="align: right"]4.97g[/TD]
[TD="align: right"]6.29g[/TD]
[TD="align: right"]0.38g[/TD]
[TD="align: right"]74kcal[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]0.00g[/TD]
[TD="align: right"]0.00g[/TD]
[TD="align: right"]0.00g[/TD]
[TD="align: right"]0.00g[/TD]
[TD="align: right"]0.00g[/TD]

</tbody>
Sheet7

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]E3[/TH]
[TD="align: left"]=VLOOKUP($C3,INDIRECT(VLOOKUP($B3,Table8,2,FALSE)),COLUMNS($E3:E3)+2,FALSE)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]


Put the formula in E3 and drag down and right as needed.

And to add to what Steve and WBD said, if you actually name the tables "Bread_Cereal_Rice_Pasta" and "Vegetables", etc., then the formula would just be:
=VLOOKUP($C3,INDIRECT($B3),COLUMNS($E3:E3)+2,FALSE)

The problem at this point is how to sum the values. With the g or kcal, it makes the values alphanumeric. It would probably be easier to change the headings on your tables to "Carbs (g)" and just put the numbers in the cell. Let us know what you think.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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