Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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

Written by Allen Wyatt (last updated March 27, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


3

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, 2016, 2019, and Excel in Microsoft 365. 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

Extracting E-mail Addresses from Hyperlinks

If you have a list of hyperlinked e-mail addresses in a worksheet, you may want to extract the addresses from those ...

Discover More

Turning Off Paste Options

Paste some information into a worksheet and Excel helpfully displays some options related to the paste operation. If you ...

Discover More

Skipping Hidden Rows in a Macro

As your macro processes information in a worksheet, you may want to make sure that it skips over rows that are hidden. ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Removing Duplicates at a Reduced Precision Level

The precision of numeric values you display in a worksheet can be less than what is actually maintained by Excel. This ...

Discover More

Entering Formulas in Excel

The primary way you signify that you are entering a formula is to start a cell entry with an equal sign. The equal sign ...

Discover More

Finding the Nth Occurrence of a Character

The FIND and SEARCH functions are great for finding the initial occurrence of a character in a text string, but what if ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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}] (all 7 characters, in the sequence shown) 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 8 + 0?

2023-05-29 08:30:36

Mohit

Thanks a lot


2021-03-28 10:01:05

Col Delane

With the introduction of multiple criteria functions (e.g. SUMIFS, COUNTIFS, AVERAGEIFS) in Xl2007, no-one should still be using the old single criterion functions (SUMIF, COUNTIF, AVERAGEIF)


2021-03-27 10:29:39

Gregory Felts

Also works with COUNTIFS Solved a problem I had using a DATE (in Col "B")and a category from my pivot table (in Cell "M7") together, Here is the formula I came up with using information from the pivot table. 44196 is equal to Dec 31, 2020. Formula looks at the Category If it is equal to (ALL) then it places N/A in the cell which has the formula, If it is equal to one of the listed categories (in this example M7 is equal to VCC which stands for Visa Credit Card), then it counts only the dates PRIOR to Dec 31, 2020 that match the category VCC. Places this number with the word "Times" trailing . In my example it shoes me that I Used My Visa Credit Card "19 Times" prior to Dec 31, 2020. I stated the Spread sheet Jan 1, 2020. I use the same formula with ">" to give me Counts for 2021. Both together tell me how many times I have use the VISA card.

IF($M$7="(all)","N/A",COUNTIFS($B$5:$B$2000,"<="&44196,$C$5:$C$2000,"="&$M$7)&" Times")

I am retired (almost 10 years now) and no longer use EXCEL in an office/corporate environment, But I like to challenge myself using it to track my finances using Excel. I look forward to Allen's Tips to make me think AND keep my mind active. Thank you ALLEN.


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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.