by Allen Wyatt
(last updated April 14, 2018)
Amol has 1,000 values in an Excel worksheet, occupying 100 rows of 10 columns each. Each value in this range is an integer value between 0 and 99. Amol needs a way to count and display all the values which are odd and greater than 50.
There are a few ways you can go about counting and displaying, but it is important to understand that these are different tasks. Perhaps the best way to display those values that fit the criteria is to use conditional formatting. You can add a conditional formatting rule to each cell that will make bold or otherwise highlight the desired values. Follow these steps:
Figure 1. The New Formatting Rule dialog box.
Figure 2. The Format Cells dialog box.
If you prefer, you could also use the following formula in step 6:
To get the count of cells that fit the criteria, you could use an array formula:
This formula assumes that the range of cells you want to analyze are named MyCells. Don't forget to enter the cell using Ctrl+Shift+Enter. If you don't want to use an array formula, you could use the following:
You could also use a macro to derive both the cells and the count. The following is a simple version of such a macro; it places the values of the cells matching the criteria into column M and then shows a count of how many cells there were:
Sub SpecialCount() Dim c As Range Dim i As Integer i = 0 For Each c In Range("A2:J101") If c.Value > 50 And c.Value Mod 2 Then i = i + 1 Range("L" & i).Value = c.Value End If Next c MsgBox i & " values are odd and greater than 50", vbOKOnly End Sub
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12597) applies to Microsoft Excel 2007, 2010, 2013, and 2016.
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!
When using an Excel worksheet to store data (such as names and phone numbers), you may need a way to easily look up a ...Discover More
Need to count the number of cells in a range that are not blank? You can use the COUNTA function of a more complex ...Discover More
When working with large amounts of data, it is a good idea to make sure that the data all consistently follows a pattern. ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.