Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Cell and Name References in COUNTIF.

# Cell and Name References in COUNTIF

by Allen Wyatt
(last updated December 26, 2015)

Larry has a worksheet that uses the COUNTIF function extensively. A typical use would be similar to the following:

```=COUNTIF(B5:B25,">=2")
```

This works fine, but Larry would like to specify the second parameter using a cell or name reference, as in ">=B3" or ">=Goal". Problem is, Larry can't get those types of references to work.

Indeed, if you use the following syntax for COUNTIF, you will not get the results you want:

```=COUNTIF(B5:B25,">=B3")
```

The reason is because everything within the quotes is considered to be part of a string literal. In other words, B3 doesn't (in this case) represent a cell reference, but the two characters B and 3.

The solution is to take the cell reference outside of the quote marks, in this manner:

```=COUNTIF(B5:B25,">=" & B3)
```

In this case the B3 is not literal, but a reference to the contents of cell B3. If, for instance, cell B3 contains the value 49, then this instance of COUNTIF is translated in this manner:

```=COUNTIF(B5:B25,">=49")
```

If you want to use a cell reference in the formula, and you will be copying that cell reference elsewhere in your worksheet, then you may want to make sure that you use an absolute reference to the cell, as in this usage:

```=COUNTIF(B5:B25,">=" & \$B\$3)
```

That way you can copy the formula without Excel changing the B3 cell reference to some other cell. You can similarly use a named cell reference in your formula using the same technique:

```=COUNTIF(B5:B25,">=" & Goal)
```

If you prefer, you could also simply put a criteria for COUNTIF in the cell you are referencing. For instance, cell B3 could contain the text ">=49", without the quote marks. You could then simplify your use of COUNTIF in this manner:

```=COUNTIF(B5:B25,B3)
```

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11417) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Cell and Name References in COUNTIF.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Eliminating "Before Spacing" at the Top of a Page

When formatting paragraphs in Word, you have several options to adjust the spacing before, within, and at the end of each ...

Discover More

Checking All Cell Formatting in VBA

When your macro checks the formatting used for a cell, it needs to be careful that the type of formatting being checked ...

Discover More

When you are working in Drive, the program makes it easy to see the files to which you have access. Normally, shared ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

##### More ExcelTips (ribbon)

Returning Zero When a Referenced Cell is Blank

Reference a cell in a macro, and if that cell is blank Excel normally equates that to a zero value. What if you don't ...

Discover More

Calculating Statistical Values on Different-Sized Subsets of Data

Discovering different ways to analyze your data can be a challenge. Here's how to work with arbitrary subsets of a large ...

Discover More

Identifying Digit-Only Part Numbers Excluding Special Characters

When working with data in Excel, you often need to determine if that data meets criteria that you specify. This tip ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four minus 2?

2017-05-04 17:38:12

Wanda Smith

I'm wanting to learn how to set tickler/alert notifications for instance. I need to be alerted within 90 days of a lease being up for renewal.
This would be in Excel 2011 for Mac.
Thank you so much!!!!

2017-04-04 11:38:11

Renee

Thank you Allen! Separating out the formula using an &, and re-arranging the "s solved my countif formula issue.

2017-01-12 10:51:14

Rickey Hargrave

Thank you, Peter. This really helps.

2017-01-11 11:22:53

Peter Atherton

Try this

Time CCM-DNR Blue Death Request Follow-Up Total
7:59 0 0 0 0 0 0
16:00 4 2 3 7 1 17
23:59:00 3 0 1 1 0 5
Totals 7 2 4 8 1 22
Formulas
L2 =SUMPRODUCT(--(\$F\$2:\$F\$23<=\$K2)*(\$G\$2:\$G\$23=L\$1))
L3 =SUMPRODUCT(--(\$F\$2:\$F\$23<=\$K3)*(\$F\$2:\$F\$23>=\$K\$2)*(\$G\$2:\$G\$23=L\$1))
L4 =SUMPRODUCT(--(\$F\$2:\$F\$23>\$K\$3)*(\$F\$2:\$F\$23<=\$K4)*(\$G\$2:\$G\$23=L\$1))

2017-01-11 07:49:51

Rhonda

Thank you Peter and Micky. Peter, your formula is cleaner than my original, but it still gives me the result 2 instead of 3. Cell 6 is definitely included in my range. I'm puzzled about why Excel doesn't see that value.

Micky, your array formula works. I don't really understand why, but at this point I don't care! Ha!

2017-01-11 05:57:11

Michael (Micky) Avidan

@Rhonda,
Try my suggestion shown in the attached picture.
(see Figure 1 below)
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL

Figure 1.

2017-01-10 18:47:07

Peter Atherton

Rhonda

Your formula works well and you need the stars. Here is another formula to search for the value in B1
=COUNTIF(Digits,"=*"&B1&"*")

Are you sure that cell 6 is included in the range?

2017-01-09 17:01:21

Rickey Hargrave

I use this formula to determine which Chaplain (in this case Chuck) handled (Death calls).
=COUNTIFS(\$D\$4:\$D\$1549,"Chuck",\$I\$4:\$I\$1549,"Death")
Now to figure out how to put in the time parameters.

2017-01-09 16:57:20

Rickey Hargrave

I have a large spreadsheet and want to know the time periods calls come in. Between 00:00 and 07:59; 08:00 - 16:00; and 16:01 - 00:00. how many deaths occur between those hours, how many "Requests", etc. Here is the spreadsheet portion.
Date Chaplain Age Sex Room Time In Reason FH / Notes
1/1/2016 Chuck 78 m 201 8:30 CCM-DNR
1/1/2016 Chuck 58 m 232 9:15 CCM-DNR
1/1/2016 Chuck 88 f 205 19:00 CCM-DNR
1/1/2016 Chuck 88 f 401 8:00 Code Blue
1/1/2016 Chuck 72 m ER 14:00 Code Blue SI/GSW
1/1/2016 Chuck 83 f 833 12:15 Death American
1/1/2016 Chuck 58 m 232 17:10 Death Wise
1/1/2016 Chuck 69 m 8:45 Follow-Up
1/1/2016 Chuck 69 f 601 10:40 Request Patient
1/1/2016 Chuck 63 m 211 15:40 Request Family
1/1/2016 Chuck 69 m 218 16:50 Request Family
1/2/2016 Chuck 65 m 209 12:15 CCM-DNR
1/2/2016 Chuck 61 m 213 13:55 CCM-DNR
1/2/2016 Chuck 94 f 825 17:15 CCM-DNR
1/2/2016 Chuck 78 m 803 12:45 Death Waldo
1/2/2016 Chuck 69 f 601 10:40 Request Family
1/2/2016 Chuck 65 m 624 11:00 Request Family
1/2/2016 Chuck 49 f 217 11:30 Request Family
1/2/2016 Chuck 63 m 211 11:45 Request Family
1/2/2016 Chuck 86 f 220 14:40 Request Family
1/3/2016 Chuck 90 m 813 18:15 CCM-DNR
1/3/2016 Chuck 80 m 703 12:50 Death Bratcher

2016-08-19 04:20:16

alok

Good tips, really work.

2016-05-06 11:37:02

Rhonda

In a named range ("DIGITS"), I'm trying to count how many times 10388552 appears. I'm using the formula =COUNTIF(DIGITS,"=*10388552*").

The data looks like this:
cell 1: 10388596, 10388498, 10388552, 10385922
cell 2: 10388596, 10388498, 10388552, cell 3: 10385922
cell 4: 10388596, 10388498
cell 5: 10388596, 10388498
cell 6: 10388552

The result should be 3, but it's giving me 2. It will not count the value in cell 6 unless I take out the * in the formula.

2016-01-07 09:39:39

AK

Thanks for this tip. I have spent hours working trial and error to get this kind of criteria to work. I don't do it a lot so I don't always remember where I've done one before and have to recreate the "wheel" each time. I'm putting this one in my personal help files.

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.