Share via

Using the COUNTIF function

Anonymous
2012-07-31T20:54:36+00:00

I am trying to count the number of hospital rooms on a certain floor using the COUNTIF function.  The problem is that some of the rooms have a dash (ie 451 and 451-2) so I used "4*" and all it counted was the rooms with the dash.  How can I get the formula to include the rooms without the dash

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Ashish Mathur 101.9K Reputation points Volunteer Moderator
2012-07-31T23:18:09+00:00

Hi,

This will also count room number 503.  I beliee your formula will have to be modified to:

=COUNTIF(A:A,"=4*")+COUNTIF(A:A,">=400")-COUNTIF(A:A,">500")

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2012-07-31T21:33:52+00:00

If your room numbers are in column A, starting in cell A2, then a formula like the one below will count only the rooms that start with "4" that do not have a "-" in them.

=SUMPRODUCT(--(LEFT(A2:A34,1)="4"),--(NOT(ISNUMBER(SEARCH("-",A2:A34,1)))))

If you are trying to count ALL rooms that start with 4, then use this:

=SUMPRODUCT(--(LEFT(A2:A34,1)="4"))

HTH,

Eric

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-08-01T05:14:20+00:00

    You're correct - it would have counted any room number above 400.  I had it in my mind at the time that only one floor was dealt with on the worksheet.  But it is possible that the entire hospital could be contained on it.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-07-31T21:21:45+00:00

    Part of this is no doubt because entries like 451 are true numbers, while 451-2 and others with a dash are treated as text.  The "4*" search parameter searches for text.

    What you could do is try to add one COUNTIF() for text matches to another for Numeric matches:

    =COUNTIF(A:A,"=4*")+COUNTIF(A:A,">400")

    Or you might need ">399" if there's a room 400 that needs to be counted.

    Was this answer helpful?

    0 comments No comments