View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default Somewhat complex code to copy data from one sheet to another

On Thursday, March 14, 2013 6:54:41 AM UTC-7, GS wrote:
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


Thanks, Garry.

I'll work with the suggestions you have offered and see if can bring it together.

I see these things often in code you have written for me and others and I get frustrated because I am often unable assemble them as needed. A lack of understand of some basic fundementals on my part.

My problem is I am way smart enough to ask the right questions and way dumb enough to not understand the answer...<G

Thanks again, I'm on it.

Howard