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

Viewing Your Work Full-Screen

Want to use the maximum space possible for displaying information on screen? You'll want to learn how to use the ...

Discover More

Resizing a Text Box in a Macro

Text boxes are easy to add to a worksheet and manually resize, as needed. If you want to resize the text box in a macro, ...

Discover More

Printing the Active Document from a Macro

When you process a document in a macro, you may also want to print that document from within the same macro. Here's how ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Deleting Duplicate Text Values

Got a list of data from which you want to delete duplicates? There are a couple of techniques you can use to get rid of ...

Discover More

Counting Unique Values

Need to know a count of unique values in a range of cells? There are a couple of ways you can tackle the problem.

Discover More

Removing Dashes from ISBN Numbers

ISBN numbers are used to denote a unique identifier for a published book. If you remove the dashes included in an ISBN, ...

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 6 - 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.