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.
Written by Allen Wyatt (last updated March 27, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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.
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!
When you recalculate a worksheet, you can determine the maximum of a range of values. Over time, as those values change, ...
Discover MoreNormally you use the RAND and RANDBETWEEN functions to generate random numbers. What if you want to generate random ...
Discover MoreExcel provides several worksheet functions that can be used to count cells containing values--"particularly numeric ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments