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

Converting Field Results to Text

Fields are meant to be dynamic, providing a result based on conditions at the time they are updated. You may want to ...

Discover More

Unique Name Entry, Take Two

If you need to make sure that a column contains only unique text values, you can use data validation for the task. This ...

Discover More

Repeating Column Information on Each Page

When your table occupies lots of pages, you may want to have information in a particular column repeated on each page. ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Determining a Name for a Week Number

You could use Excel to collect data that is useful in your business. For instance, you might use it to collect ...

Discover More

Applying Range Names to Formulas

If you define your named ranges after you create your formulas, you can have Excel update those formulas to reflect the ...

Discover More

Finding the Sum of a Sequential Integer Range

In mathematics, the sum of a range of sequential integers, starting with 1, is known as a triangular number or Gaussian ...

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 nine minus 5?

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.