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 19th, 2002, 04:00 PM   #1
jereece
New Member
 
Join Date: Mar 2002
Posts: 25
Default

Lets say I have the following spreadsheet:

ColA ColB
1 pass
1 fail
1 pass
2 pass
1 pass
3 fail
2 pass

In another cell I want to count how many "1" in column A were "pass". I tried to write a count if statement, but it did not work. Here's what I tried: =((COUNTIF(A:A,"1"))*AND((COUNTIF(B:B,"pass")))). This only returns the number of 1s in collumn A.

Can anyone help with single formula?

Thanks,
Jim
jereece is offline   Reply With Quote
Old Mar 19th, 2002, 04:12 PM   #2
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

You'll want to enter the following formula and press control-shift-enter (same time) once it's in the formula bar:

=SUM((A1:A65536=1)*(B1:B65336="pass"))

Should look like this:

{=SUM((A1:A65536=1)*(B1:B65336="pass"))}

Hope this helps.

_________________
Cheers, NateO

[ This Message was edited by: NateO on 2002-03-19 15:14 ]
NateO is offline   Reply With Quote
Old Mar 19th, 2002, 04:28 PM   #3
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-03-19 15:00, jereece wrote:
Lets say I have the following spreadsheet:

ColA ColB
1 pass
1 fail
1 pass
2 pass
1 pass
3 fail
2 pass

In another cell I want to count how many "1" in column A were "pass". I tried to write a count if statement, but it did not work. Here's what I tried: =((COUNTIF(A:A,"1"))*AND((COUNTIF(B:B,"pass")))). This only returns the number of 1s in collumn A.

Can anyone help with single formula?

Thanks,
Jim
Given that the sample you provided (with labels added)

{"Studuent","Result";1,"pass";1,"fail";1,"pass";2,"pass";1,"pass";1,"fail";2,"pass"}

is in A1:B8,

you can also use:

=SUMPRODUCT((A2:A8=1)*(B2:B8="pass"))

where, if desired, 1 and pass can be in cells of their own and their cell refs then can be used in the formula.

Another way would be to use DCOUNT:

=DCOUNT(A1:B8,1,D1:E2)

where D1 houses the label 'Student', D2 the criterion/condition 1, E1 the label 'Result', and E2 the criterion/condition "pass" (without double quotes").

Aladin



[ This Message was edited by: Aladin Akyurek on 2002-03-19 15:57 ]
Aladin Akyurek is offline   Reply With Quote
Old Mar 19th, 2002, 06:03 PM   #4
jereece
New Member
 
Join Date: Mar 2002
Posts: 25
Default

Thanks. The only one I could get to work correctly was the SUMPRODUCT, but it works great.

Thanks again.
Jim
jereece is offline   Reply With Quote
Old Mar 19th, 2002, 08:01 PM   #5
kinkyparamour
Board Regular
 
Join Date: Feb 2002
Location: Florida
Posts: 82
Default

If you take the formula from Nate and correct the type o it works fine.....

=SUM((A1:A65336=1)*(B1:B65336="pass"))
kinkyparamour is offline   Reply With Quote
Old Mar 19th, 2002, 09:09 PM   #6
NateO
Legend
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
Default

Nice catch Kinky, I thought I lined both ranges up but no such luck.
__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Feb 19th, 2005, 04:42 PM   #7
jereece
New Member
 
Join Date: Mar 2002
Posts: 25
Default

When I use =SUM((A1:A65336=1)*(B1:B65336="pass")), I get a result of 1 when clearly I have several that match.


=SUMPRODUCT((A2:A21=1)*(B2:B21="pass")) still works however.

Thanks,
Jim
jereece is offline   Reply With Quote
Old Feb 19th, 2005, 04:49 PM   #8
just_jon
Legend
 
just_jon's Avatar
 
Join Date: Sep 2002
Location: Alabama/State of Disarray
Posts: 10,473
Default

First - do you really need to look at 65536 rows?

SUMPRODUCT instead of SUM, and shorten the range -- SUMPRODUCT does not like whole column arrays.
__________________
just_jon
Book of the Month: I'm Not Really an MVP, I Just Play One on TV [j. jon, 2004]
just_jon is offline   Reply With Quote
Old Feb 19th, 2005, 04:49 PM   #9
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
Originally Posted by jereece
When I use =SUM((A1:A65336=1)*(B1:B65336="pass")), I get a result of 1 when clearly I have several that match.
The range in A must be numeric and the range in B should not have any spaces or non-visible chars around the values it houses. Try to run ASAP Utilities or the TrimAll macro (available in some threads on this site) on the ranges of interest to exclude that problem.
Aladin Akyurek is offline   Reply With Quote
Old Feb 21st, 2005, 02:46 PM   #10
jereece
New Member
 
Join Date: Mar 2002
Posts: 25
Default

=SUMPRODUCT((A2:A8=1)*(B2:B8="pass"))

This seems to work for me. One last question, is there a way to get this to work with wild cards (i.e. "*pass*")? I have one database I want to use this with and the entries are not 100% consistent. If I could use a wild card, that would eliminate my problem.

I tried for example =SUMPRODUCT((A2:A8=1)*(B2:B8,*pass*)) but keep getting error messages.

Can anyone help?

Thanks,
Jim
jereece 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 -4. The time now is 03:36 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 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