Counif function

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
How to calculate the total fruits consumed by 3 students within 5 days ? Please take note each student can consume more than 1 per day ?

Student 1
Student 2
Student 3
Day 1
apple / kiwi
orange
apple
Day 2
orange
honey dew
apple / kiwi
Day 3
kiwi
apple
orange
Day 4
honey dew / kiwi
kiwi
kiwi
Day 5
apple
kiwi
apple

<tbody>
</tbody>


Final Output


Apple : 6
Kiwi : 7
Orange : 3
Honey Dew: 2
 
Thanks markmzz works perfectly, I think the originator will be happy, I can see some use for this formula in my case.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe this:

Layout

Student 1
Student 2
Student 3
Day 1
apple / kiwi
orange
apple
Day 2
orange / myapple
honey dew
apple / kiwi
Day 3
kiwi / kiwi
apple
orange
Day 4
honey dew/kiwi
kiwi
kiwi
Day 5
apple
kiwi
apple
*
Final Output
Without repetition
With repetition
Apple
6
6
Kiwi
7
8
Orange
3
3
Honey Dew
2
2
************
*********************
***************
***********

<tbody>
</tbody>


Formulas

Code:
In B9 enter this formula

=SUMPRODUCT(--ISNUMBER(SEARCH(" "&A9&" /"," "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")))

In C9 enter this formula

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&UPPER(TRIM(SUBSTITUTE($B$2:$D$6,"/"," / ")))&" /"," "&UPPER($A9)&" /","")))/
LEN(" "&$A9&" /"))


Markmzz
?

Thanks for your effort . Is that possible to simplify the formula that works for repetition ?
 
Upvote 0
Hi Ryan,

Sorry, but, until now, I don't know how to do that.

By the way, what is the problem with that formula?

Markmzz

Hi Mark,

Using your method for repetition, I can obtain value for kiwi but not for other fruits. Also, why in the name must be CAP in the final output ? Kindly clarify. Thanks
 
Upvote 0
Hi Mark,

Using your method for repetition, I can obtain value for kiwi but not for other fruits. Also, why in the name must be CAP in the final output ? Kindly clarify. Thanks

Hi Ryan,

Here the formula Works (apple and kiwi). Look at this:

Layout

Student 1Student 2Student 3
Day 1apple / kiwiorangeapple
Day 2orange / myapplehoney dewapple / kiwi
Day 3kiwi / kiwiappleorange
Day 4honey dew/kiwikiwikiwi
Day 5apple / kiwi/Applekiwiapple
*
Final OutputWith repetitionWithout UPPER
Apple71
Kiwi90
Orange30
Honey Dew20
*******************************************************

<colgroup><col width="67" style="width: 50pt; mso-width-source: userset; mso-width-alt: 2450;"> <col width="93" style="width: 70pt; mso-width-source: userset; mso-width-alt: 3401;"> <col width="80" style="width: 60pt; mso-width-source: userset; mso-width-alt: 2925;"> <col width="62" style="width: 47pt; mso-width-source: userset; mso-width-alt: 2267;"> <tbody>
</tbody>

Formulas

Code:
In B9

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&UPPER(TRIM(SUBSTITUTE($B$2:$D$6,"/"," / ")))&" /"," "&UPPER($A9)&" /","")))/
LEN(" "&$A9&" /"))

In C9

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /"," "&$A9&" /","")))/
LEN(" "&$A9&" /"))

PS: see the difference with and without UPPER function. The function SUBSTITUTE need that function to work like you want.


Markmzz
 
Upvote 0
Hi Ryan,

Here the formula Works (apple and kiwi). Look at this:

Layout

Student 1
Student 2
Student 3
Day 1
apple / kiwi
orange
apple
Day 2
orange / myapple
honey dew
apple / kiwi
Day 3
kiwi / kiwi
apple
orange
Day 4
honey dew/kiwi
kiwi
kiwi
Day 5
apple / kiwi/Apple
kiwi
apple
*
Final Output
With repetition
Without UPPER
Apple
7
1
Kiwi
9
0
Orange
3
0
Honey Dew
2
0
************
*****************
***************
***********

<tbody>
</tbody>

Formulas

Code:
In B9

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&UPPER(TRIM(SUBSTITUTE($B$2:$D$6,"/"," / ")))&" /"," "&UPPER($A9)&" /","")))/
LEN(" "&$A9&" /"))

In C9

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /"," "&$A9&" /","")))/
LEN(" "&$A9&" /"))

PS: see the difference with and without UPPER function. The function SUBSTITUTE need that function to work like you want.


Markmzz

But it wouldn't work for me, all value is 0. Should I use ctrl+shft+del to enter the formula ?

What is purpose for using "/", " / " & " /" ? Are they the same ?

Here is the code I modified from yours

Code:
SUMPRODUCT((LEN(" "&TRIM(SUBSTITUTE($A$2:$C$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&TRIM(SUBSTITUTE($A$2:$C$6,"/"," / "))&" /"," "&$A9&" /","")))/LEN(" "&$A9&" /"))
 
Upvote 0
But it wouldn't work for me, all value is 0. Should I use ctrl+shft+del to enter the formula ?

What is purpose for using "/", " / " & " /" ? Are they the same ?

Here is the code I modified from yours

Code:
SUMPRODUCT((LEN(" "&TRIM(SUBSTITUTE($A$2:$C$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&TRIM(SUBSTITUTE($A$2:$C$6,"/"," / "))&" /"," "&$A9&" /","")))/LEN(" "&$A9&" /"))

Hi Ryan,

You need to use my formula (with UPPER function - did you read my last post - look at the column Without UPPER in that post).

Now, look at this (with your layout):

Layout

ABC
1Student 1Student 2Student 3
2apple / kiwiorangeapple
3orange / myapplehoney dewapple / kiwi
4kiwi / kiwiappleorange
5honey dew/kiwikiwikiwi
6apple / kiwi/Applekiwiapple
7*
8FruitsFinal Output
9Apple7
10Kiwi9
11Orange3
12Honey Dew2
*******************************************************

<colgroup><col width="27" style="width: 20pt; mso-width-source: userset; mso-width-alt: 987;"> <col width="93" style="width: 70pt; mso-width-source: userset; mso-width-alt: 3401;" span="3"> <tbody>
</tbody>



Formula

Code:
In B9 (use only Enter to enter the formula)

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($A$2:$C$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&[COLOR="#FF0000"]UPPER[/COLOR](TRIM(SUBSTITUTE($A$2:$C$6,"/"," / ")))&" /"," "&[COLOR="#FF0000"]UPPER[/COLOR]($A9)&" /","")))/
LEN(" "&$A9&" /"))

"What is purpose for using "/", " / " & " /" ? Are they the same ?"

I used this to find the exactly word that you want (like apple and not myapple).

Markmzz
 
Upvote 0
Hi Ryan,

You need to use my formula (with UPPER function - did you read my last post - look at the column Without UPPER in that post).

Now, look at this (with your layout):

Layout

A
B
C
1
Student 1
Student 2
Student 3
2
apple / kiwi
orange
apple
3
orange / myapple
honey dew
apple / kiwi
4
kiwi / kiwi
apple
orange
5
honey dew/kiwi
kiwi
kiwi
6
apple / kiwi/Apple
kiwi
apple
7
*
8
Fruits
Final Output
9
Apple
7
10
Kiwi
9
11
Orange
3
12
Honey Dew
2
****
*****************
*****************
*****************

<tbody>
</tbody>


Markmzz

This is the output I get
Apple
7
Kiwi
9
Orange
0
Honey Dew
0

<tbody>
</tbody>


Why the value for orange & honey dew is 0 ? Does this mean I have to ensure all fruits is repeated before I use your formula?
 
Last edited:
Upvote 0
This is the output I get
Apple
7
Kiwi
9
Orange
Honey Dew

<tbody>
</tbody>


Why the value for orange & honey dew is 0 ? Does this mean I have to ensure all fruits is repeated before I use your formula?

Look at your PM Box.

Markmzz
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,937
Members
449,480
Latest member
yesitisasport

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