Finding Odd Values Greater Than 50

Written by Allen Wyatt (last updated December 30, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

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:

  1. Select the cells that contain your data.
  2. Display the Home tab of the ribbon.
  3. Click the Conditional Formatting tool in the Styles group. Excel displays a palette of options related to conditional formatting.
  4. Click New Rule. Excel displays the New Formatting Rule dialog box. (See Figure 1.)
  5. Figure 1. The New Formatting Rule dialog box.

  6. In the Select a Rule Type area at the top of the dialog box, choose Use a Formula To Determine Which Cells to Format.
  7. In the formula box enter the formula =AND(MOD(A1,2),A1>50).
  8. Click the Format button. Excel displays the Format Cells dialog box. (See Figure 2.)
  9. Figure 2. The Format Cells dialog box.

  10. Use the controls in the dialog box to modify the formatting, as desired.
  11. Click OK to close the Format Cells dialog box.
  12. Click OK to close the New Formatting Rule dialog box. The formatting is applied to the range of cells you selected in step 1.

If you prefer, you could also use the following formula in step 6:

=AND(ISODD(A1),A1>50)

To get the count of cells that fit the criteria, you could use an array formula:

=SUM(MOD(MyCells,2)*(MyCells>50)

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. (This is not necessary if you are using Excel in Microsoft 365; just press Enter.) If you don't want to use an array formula, you could use the following:

=SUMPRODUCT((MOD(MyCells,2)*(MyCells>50))

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

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12597) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

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

Using Only Odd Page Numbers

Do you need to number the pages of your document using only odd page numbers? Word doesn't provide a way to do this, but ...

Discover More

Controlling Overtype Mode

Some people like to have Word replace previous information as they type; this is called 'overtype mode.' You can control ...

Discover More

Checking for Data Entry Errors for Times

When you enter a time value into Excel, the program tries its hardest to make the value into a valid time. This can lead ...

Discover More

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!

More ExcelTips (ribbon)

Calculating the Median Age of a Group of People

Suppose you have a worksheet that contains a list of ages and then a count of people who correspond with those ages. You ...

Discover More

Formatting Canadian Postal Codes

Postal codes in Canada consist of six characters, separated into two groups. This tip explains the format and then shows ...

Discover More

Picking Different Random Numbers from a Range

It is not unusual to need to select two random items from a list. There are a couple of ways you can approach the task; ...

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 2 + 2?

2023-12-30 09:51:48

J. Woolley

Re. the formula (which was missing the final parenthesis)
    =SUM(MOD(MyCells,2)*(MyCells>50))
the Tip says, "Don't forget to enter the cell using Ctrl+Shift+Enter." I don't think this is necessary because the formula does not return an array.


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.