COUNTIF formula

DarrenF

Board Regular
Joined
Jun 9, 2014
Messages
90
Hello,

I'm trying to use the following formula:

=COUNTIF(D2,"Vanilla")+COUNTIF(D2,"BlueBerry")+COUNTIF(D2,"Cherry")

I also would like to add if cell (D2) is blank, then use the data in Cell (C2). I'm not sure how to write that part of the formula.

Example Data Sheet:

C D
1Cherry
2Vanilla
3Blueberry
4Strawberry
5Banana
6Vanilla
7Banana
8Vanilla
9Blueberry

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Why are you using COUNTIF if you are just ever looking at one single cell at a time?
Also, will both columns C and D ever both be populated at the same time?

If not, maybe this will give you what you want:
Code:
=IF(OR(C2&D2="Vanilla",C2&D2="Blueberry",C2&D2="Cherry"),1,0)
 
Upvote 0
I think I got it:

=IF(OR(AND(D2="",C2="Vanilla"),D2="Vanilla",D2="Blueberry",D2="Cherry"),1,0)
 
Upvote 0

Excel 2010
CDEFGHI
1Count by criteriaBlueberry
2Cherry111Cherry
3Vanilla111Vanilla
4Blueberry111
5Strawberry000
6Banana000
7Cherry111
8Banana000
9VanillaVanilla111
10Blueberry111
11
5d
Cell Formulas
RangeFormula
E2=IF(D2="",OR(C2={"Vanilla","BlueBerry","Cherry"}),OR(D2={"Vanilla","BlueBerry","Cherry"}))+0
F2=IF(D2="",COUNTIF(rCriteria,C2),COUNTIF(rCriteria,D2))
G2=COUNTIF(rCriteria,IF(D2="",C2,D2))
Named Ranges
NameRefers ToCells
rCriteria='5d'!$I$1:$I$3
 
Upvote 0

Forum statistics

Threads
1,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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