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:

[TABLE="width: 253"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD] C[/TD]
[TD] D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]Cherry[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]Vanilla[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[TD]Blueberry[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][/TD]
[TD]Strawberry[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Banana[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Vanilla[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][/TD]
[TD]Banana[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD][/TD]
[TD]Vanilla[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD][/TD]
[TD]Blueberry[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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

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,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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