MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 7th, 2009, 05:30 PM   #1
richard hales
 
Join Date: Feb 2009
Posts: 48
Default formlua code needed???

hi all
am looking for a formlua which will leave me a number if a code number is put into a cell and if no code number is put in to return as blank...
Cell A1 to Cell A4 is the cell's area
Cell A5 will hold the = from the code or be blank.
codes:
S2 =2
S6 =6
S7 =7
S8 =8
H2 =2
H6 =6
H7 =7
H8 =8
richard hales is offline   Reply With Quote
Old Mar 7th, 2009, 05:33 PM   #2
barry houdini
MrExcel MVP
 
Join Date: Mar 2005
Location: England
Posts: 14,292
Default Re: formlua code needed???

Hello richard,

Do you mean that there will be codes in all 4 cells A1 to A4. Should A5 have the "sum" of all the codes entered?
barry houdini is offline   Reply With Quote
Old Mar 7th, 2009, 05:41 PM   #3
richard hales
 
Join Date: Feb 2009
Posts: 48
Default Re: formlua code needed???

Hi Barry
Thanks for repling am looking for, should i enter any of the codes into any of the cell's A1 to A4 cell A5 will only give me the = number or stay blank you could say that Cell A5 will look in A1 to A4 for a answer.
richard hales is offline   Reply With Quote
Old Mar 7th, 2009, 05:47 PM   #4
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: formlua code needed???

Dear richard hales,

I am not sure what you mean when you say “Cell A1 to Cell A4 is the cell's area”.

But this formula would work for checking A1 for a code and then returning the associated number to the cell:

=IF(A1="","",VLOOKUP(A1,{"S2","2";"S6","6";"S7","7";"S8","8";"H2","2";"H6","6";"H7","7";"H8","8"},2,0))

Or if you had the codes in column C and numbers in column D (C3:D10), this would work:

=IF(A1="","",VLOOKUP(A1,C3:D10,2,0))

If as barry houdini suggested you need a formula for summing this could work:

Enter with the key strokes “Ctrl + Shift + Enter”:

=IF(AND(A1:A4=""),"",SUM((A1:A4={"S2";"S6";"S7";"S8";"H2";"H6";"H7";"H8"})*({"2";"6";"7";"8";"2";"6";"7";"8"})))

Or this if values are in cells:

Enter with the key strokes “Ctrl + Shift + Enter”:

=IF(AND(A1:A4=""),"",SUM((A1:A4=C3:C10)*(D3:D10)))
__________________
Sincerely, Mike Gel Girvin

Last edited by mgirvin; Mar 7th, 2009 at 05:51 PM.
mgirvin is offline   Reply With Quote
Old Mar 7th, 2009, 05:48 PM   #5
barry houdini
MrExcel MVP
 
Join Date: Mar 2005
Location: England
Posts: 14,292
Default Re: formlua code needed???

The simplest way would probably to enter your codes somewhere on the worksheet, e.g. in Y2:Y9 with the corresponding values in Z2:Z9 then formula in A5 could be

=IF(COUNTA(A1:A4),SUMPRODUCT(SUMIF(Y2:Y9,A1:A4,Z2:Z9)),"")
barry houdini is offline   Reply With Quote
Old Mar 7th, 2009, 05:58 PM   #6
richard hales
 
Join Date: Feb 2009
Posts: 48
Default Re: formlua code needed???

Thanks Barry it works just the way i need it to... what can i say but your the man.
richard hales is offline   Reply With Quote
Old Mar 7th, 2009, 06:01 PM   #7
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: formlua code needed???

Dear barry houdini,

I like the COUNTA for the true false test, it avoids the AND(A1:D1="") Ctrl + Shift + Enter!

But I could not get this to work:

SUMPRODUCT(SUMIF(Y2:Y9,A1:A4,Z2:Z9))

Let me make sure that I got the arguments right in the SUMIF:

Y2:Y9 will be the codes S2, S6. etc.

A1:A4 has the codes to lookup

Z2:Z9 had the numbers to return and then add.

And another question:

You used SUMPRODUCT(SUMIF(Y2:Y9,A1:A4,Z2:Z9)) to avoid "Ctrl + Shift + Enter", right? And this is because the SUMPRODUCT handles arrays without Ctrl + Shift + Enter?
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Old Mar 7th, 2009, 06:01 PM   #8
richard hales
 
Join Date: Feb 2009
Posts: 48
Default Re: formlua code needed???

mgirvin.. Thanks the formlua works fine..cheers
richard hales is offline   Reply With Quote
Old Mar 7th, 2009, 10:11 PM   #9
barry houdini
MrExcel MVP
 
Join Date: Mar 2005
Location: England
Posts: 14,292
Default Re: formlua code needed???

Quote:
Originally Posted by mgirvin View Post
Dear barry houdini,

I like the COUNTA for the true false test, it avoids the AND(A1:D1="") Ctrl + Shift + Enter!

But I could not get this to work:

SUMPRODUCT(SUMIF(Y2:Y9,A1:A4,Z2:Z9))

Let me make sure that I got the arguments right in the SUMIF:

Y2:Y9 will be the codes S2, S6. etc.

A1:A4 has the codes to lookup

Z2:Z9 had the numbers to return and then add.

And another question:

You used SUMPRODUCT(SUMIF(Y2:Y9,A1:A4,Z2:Z9)) to avoid "Ctrl + Shift + Enter", right? And this is because the SUMPRODUCT handles arrays without Ctrl + Shift + Enter?
I think all of your assumptions are correct Mike. Yes, you could use

=SUM(SUMIF(Y2:Y9,A1:A4,Z2:Z9))

....but it would require CSE. I've got nothing against "array entered" formulas but obviously some people prefer to avoid them or don't know how to apply them so if it's simple enough to do I'll try to avoid them.
barry houdini is offline   Reply With Quote
Old Mar 8th, 2009, 12:13 AM   #10
mgirvin
 
Join Date: Dec 2005
Location: Seattle, WA
Posts: 321
Default Re: formlua code needed???

Dear barry houdini,

Got it! It does make sense to provide a non CSE, because most don't do the CSE.
In addition to the COUNTA on/off trick, thanks for the SUMIF inside the SUMPRODUCT trick also!
Two new tricks for my Excel tool box!
__________________
Sincerely, Mike Gel Girvin
mgirvin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 07:44 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes