Count If works selectively

altrudel

New Member
Joined
Sep 26, 2011
Messages
4
The Goal: To total the amount of days off and requested days off in a schedule.
The Problem -
COUNTIF is working great to tabulate the requests off:
=COUNTIF(B3:H15,"OFF-R")
and boom! It counts all the requests off perfectly!

however

when i use the same function in the next cell over but replace "OFF-R" with just "OFF" it comes back with nothing.
Could it have something to do with the text formatting?
I just do not understand why it works just fine for one string of text, but fails for the other string of text. I've tried various wildcards, COUNTIFS, reformatting of text...I just can't figure it out.
3 minutes away from mental meltdown.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the board!

Do any of the cells in the range actually contain the text "OFF" ?

Note that "OFF-R" will not be counted as it's not exactly the same as the criteria.

Also check the range of the second formula, depending on how you copied it you may find that it's looking at C3:I15 instead , so entries in column B will be missed.
 
Upvote 0
Thank you for the quick reply!!!
i confirmed that there are 9 cells in the range that contain the text "OFF" or "OFF " (space after the letters). I wonder if excel is reading those as something different, though?
I verified that its counting in the correct range.
After digging through all the blogs, I saw that "ctrl+shift+enter" can help function work properly, so I attempted doing that instead of simply "entering". and now i'm totally baffled because it counted 1 of the 9 when I did that.
I have tried changing the cells that say "OFF" so they say something totally different to see if that would work. No go. I have tried to change the formatting so that they are text and general. Nothing. I have tried changing the format of the sheet that each cell is referencing. Still nothing.
This was my latest attempt that counted 1 of the "OFF" items.
=COUNTIFS(B3:H15,"OFF ", B3:H15,"OFF ")
I event tried replacing "off" in the formual with a cell reference (and in that cell i put 'off') but still no go.
 
Upvote 0
=COUNTIF(B3:H15,""=D1) (with d1 = "off")
a fail

=COUNTIF(B3:H15,D1) (with d1= off ) - space after "off"
counts 1 in first row- fails other 8

=COUNTIF(B3:H15,D1) (with d1=off)
a fail
 
Upvote 0
Trying to clarify things you mentioned above, and answer your original question.

Shift Ctrl Enter is used for array formula, with a non-array formula that can produce erratic results.

With a criteria "OFF", any cells containing "OFF " would not be counted.

Countifs would look for both "OFF" and "OFF " (2 different criteria) in the same cell, this will always result in 0.

You could use a wildcard, =COUNTIF(B3:H15,"OFF*") but this would also count "OFF-R", etc, which I assume should be ignored as they have already been counted.

That leaves adding up several countif results, either the long way

=COUNTIF(B3:H15,"OFF")+COUNTIF(B3:H15,"OFF ")

Or using an array constant

=SUM(COUNTIF(B3:H15,{"OFF","OFF "}))

Note that this method has to be nested in SUM() or it will only return the result of the first criteria.

Hope that helps.
 
Upvote 0
If it's an actual space at the end (or even more than one space) you could also use TRIM, i.e.

=SUMPRODUCT((TRIM(B3:H15)="OFF")+0)
 
Upvote 0
YAY!!!!!!
the trim function worked perfectly!!!!!!

Thank you! Thank you! thank you! thank you!!!
Y'all ROCK!!! :grin:
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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