Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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: Finding the Smallest Even Value.
Written by Allen Wyatt (last updated September 28, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
Emin has a range of cells in which there can be either text or numbers. He needs a way to determine the smallest even number in the range. Emin wonders if this can be done with a formula, or if he needs a user-defined function.
There are a couple of ways you can approach this problem. One method you can try is to use the DMIN function. All that you need is to make sure that you have a header on your data column (such as "MyData") and then create a small criteria field in some out-of-the-way place. For instance, you might want to create the criteria field by placing a header (such as "Min Even") in cell F1 and place the formula =ISEVEN(MyData) in cell F2. Cell F2 evaluates to a #VALUE! error, but that is fine in this case. You can then use the following formula in a different cell:
=DMIN(A1:A100, 1, F1:F2)
There is a different formulaic approach you can take. The following checks whether a cell contains a text value or not and, based on the result, checks to see if the value is even or not.
=MIN(IF(ISNUMBER(A1:A100),IF(NOT(MOD(A1:A100,2)=0),"",A1:A100)))
This formula will work just fine in Excel 2019, 2021, and the version with Microsoft 365. If you are using an older version of Excel, you'll need to enter this as an array formula, meaning you enter it using Shift+Ctrl+Enter.
If you prefer, you can create a user-defined function that will return the desired value:
Function MinEven(rng As Range) Dim rCell As Range Dim bNotFound As Boolean Application.Volatile MinEven = 9.99 * 10 ^ 307 bNotFound = True For Each rCell In rng If Application.WorksheetFunction.IsNumber(rCell) Then If rCell Mod 2 = 0 Then If rCell < MinEven Then MinEven = rCell bNotFound = False End If End If End If Next If bNotFound Then MinEven = CVErr(xlErrNum) End Function
To use this macro, simply use the following with a cell of your worksheet:
=MinEven(A1:A100)
If there are no even numbers in the range, the function will return a #NUM! error.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (124) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Finding the Smallest Even Value.
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!
Do you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...
Discover MoreNeed to get at the next-to-last value in a column, regardless of how many cells are used within that column? This tip ...
Discover MoreIf you would like to determine how many instances of a particular word appear within a range of text, there are several ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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