Array formula to look up tables and populate them into a sheet

joshbjames

New Member
Joined
Jul 25, 2017
Messages
33
Laziness inspires this project. I am trying to generate a shopping list of ingredients. Since my family is quarantined I want an easy way to create a shopping list for the next month, but I figured this would be great going forward too.

Here is link: Recipes

Sheet "Table of Contents", column1 "Recipe" is the recipe name, column2 "Sheet" is the sheet name that contains the recipe ingredients and column3 "Add" I put an "x" if I want to add the recipe to my shopping list.

Sheet "Meal Schedule", column1 is an array formula that pulls in the recipes chosen (sheet "Table of Contents", column3). "Meal Schedule" column2 "Sheet" looks up the recipe sheet.

Sheet nRecipe, column1 is "QTY", column2 "UOM" is the unit of measure, column3 "Ingredient"

Goal: In sheet "Ingredient List" for each recipe on "Meal Schedule" I would like to pull all the values for all 3 columns ("QTY","UOM", and "Ingredient") from sheets nRecipe.

Example: On Sheet "Table of Contents" I add 2 recipes.

So if Recipe 1 Sheet "Salmon01" is
QTYUOMIngredient
2ozJalapeno Jelly
0.5tspSeasoned Salt
12ozAsparagus
1ozCrispy onions
0.5ozPecans
2eaSalmon Fillets

and Recipe 2 Sheet "Chicken01" is
QTYUOMIngredient
8ozBrussels Sprouts
0.5ozSmoked Almonds
1eaFuji Apple
1eaShallot
2tbspRoasted Red Pepper Pesto
0.5ozParmesan
2eaChicken Breast

Then in sheet "Ingredient List" I would like
QTYUOMIngredient
8ozBrussels Sprouts
0.5ozSmoked Almonds
1eaFuji Apple
1eaShallot
2tbspRoasted Red Pepper Pesto
0.5ozParmesan
2eaChicken Breast
2ozJalapeno Jelly
0.5tspSeasoned Salt
12ozAsparagus
1ozCrispy onions
0.5ozPecans
2eaSalmon Fillets

Thanks in advance for any help!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't think that you will achieve what you want with formulas, but with a macro "yes".

I would suggest putting the headings only manually into 'Ingedient List' A1:C1 (You will only need to do this once.
Mark the wanted recipes in 'Table of Contents' as you have done then run this macro.

Test in a copy of your workbook.

VBA Code:
Sub ShoppingList()
  Dim d As Object
  Dim a As Variant
  Dim c As Range
  Dim i As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  With Sheets("Table of Contents")
    For Each c In .Range("C2", .Range("C" & .Rows.Count).End(xlUp)).SpecialCells(xlConstants)
      a = Sheets(c.Offset(, -1).Value).UsedRange.Value
      For i = 2 To UBound(a)
        d(a(i, 2) & ";" & a(i, 3)) = d(a(i, 2) & ";" & a(i, 3)) + a(i, 1)
      Next i
    Next c
  End With
  With Sheets("Ingredient List")
    .UsedRange.Offset(1).ClearContents
    With .Range("A2").Resize(d.Count, 2)
      .Value = Application.Transpose(Array(d.Items, d.Keys))
      .Columns(2).TextToColumns DataType:=xlDelimited, Semicolon:=True, Comma:=False, Space:=False, Other:=False
      .Resize(, 3).EntireColumn.AutoFit
    End With
  End With
End Sub
 
Upvote 0
I don't think that you will achieve what you want with formulas, but with a macro "yes".

I would suggest putting the headings only manually into 'Ingedient List' A1:C1 (You will only need to do this once.
Mark the wanted recipes in 'Table of Contents' as you have done then run this macro.

Test in a copy of your workbook.

VBA Code:
Sub ShoppingList()
  Dim d As Object
  Dim a As Variant
  Dim c As Range
  Dim i As Long
 
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  With Sheets("Table of Contents")
    For Each c In .Range("C2", .Range("C" & .Rows.Count).End(xlUp)).SpecialCells(xlConstants)
      a = Sheets(c.Offset(, -1).Value).UsedRange.Value
      For i = 2 To UBound(a)
        d(a(i, 2) & ";" & a(i, 3)) = d(a(i, 2) & ";" & a(i, 3)) + a(i, 1)
      Next i
    Next c
  End With
  With Sheets("Ingredient List")
    .UsedRange.Offset(1).ClearContents
    With .Range("A2").Resize(d.Count, 2)
      .Value = Application.Transpose(Array(d.Items, d.Keys))
      .Columns(2).TextToColumns DataType:=xlDelimited, Semicolon:=True, Comma:=False, Space:=False, Other:=False
      .Resize(, 3).EntireColumn.AutoFit
    End With
  End With
End Sub
Thanks Peter,

I don't have excel, so I will have to convert this for google sheets, but I am excited to give this a try!
 
Upvote 0
I don't have excel, so I will have to convert this for google sheets,
Hmm, posted in 'Excel Questions' forum (I have moved it) with no mention that it is not an Excel question. :(

Whilst we do allow questions like this, please do not post them in the Excel Questions forum unless their is a direct connection to Excel.
 
Upvote 0

Forum statistics

Threads
1,223,661
Messages
6,173,647
Members
452,525
Latest member
DPOLKADOT

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