View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Somewhat complex code to copy data from one sheet to another

Suggestion...

Store your ingredients lists on a separate sheet from your meals
schedule, and name each list same as myMeal (without spaces)...

Example:
myMeal:=Beef Lasagna
IngredientsList:=BeefLasagna OR Beef_Lasagna

...so all you need to do is grab the list into an array and dump the
contents into your "Groceries Needed"...

Dim vIngrList, rngTarget As Range

Const sPrompt$ = "Select the cell where the ingredients list starts"
Const sTitle$ = "Insert Ingredients"

'Grab the ingredients list for myMeal
vIngrList = Sheets("Lists").Range(Replace(myMeal, " ", ""))
'OR
' vIngrList = Sheets("Lists").Range(Replace(myMeal, " ", "_"))

'Prompt for the location to insert the list
Set rngTarget = _
Application.InputBox(Prompt:=sPrompt, Title:=sTitle, _
Default:=ActiveCell.Address, Type:=8)

'Dump the list into the worksheet
If Not rngTarget Is Nothing Then _
rngTarget.Resize(UBound(vIngrList), 1)) = vIngrList

...where (as per your sample) myMeal is "Chili" and the ingredients are
located on "Lists" in the range named "Chili". As per my sample, myMeal
would be "Beef Lasagna" and its ingredients would be located in the
range named "BeefLasagna" (or "Beef_Lasagna") on "Lists".

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion