Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Finding Rows with Values in Two Columns.

Finding Rows with Values in Two Columns

Written by Allen Wyatt (last updated May 7, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


Adri has a worksheet that has quite a few data records in it (well over 40,000). Two of the columns on each row are supposed to be mutually exclusive—a value can be in column F or in column G, but a value should not be in column F and column G. Adri need a quick way to find any records in which there is a value in both columns F and G so she can rectify these erroneous entries.

The key here is the phrase "on each row." Audri wants to simply look at column F and G on any given row and make sure that there aren't values (any values) in both F and G. Understanding this, there are a number of different ways you can proceed. An easy way is to add a simple formula to column H, such as this:

=COUNTA(F2:G2)

Assuming you place this formula in cell H2 (just to the right of the cells being examined), the result will be either 0, 1, or 2. If both F2 and G2 are empty, then the result is 0; if either F2 or G2 is empty, then the result is 1; and if neither F2 or G2 is empty, then the result is 2. You can easily sort or filter by the results in column H to find those rows that don't have the proper count.

If you prefer a textual indicator in column H, you can use a formula such as this:

=IF(ISBLANK(F2)+ISBLANK(G2)<>1,"Error","OK")

This formula displays "Error" if there is either nothing in F and G or something in both F and G. It only displays "OK" if there is something in either F or G. With the formula in place, you can easily sort or filter to find the errant rows.

Speaking of filters, you can easily apply an AutoFilter that will show you only those rows that have something in both columns F and G. Turn on the AutoFilter tool, and then click the down-arrow at the top of column F. In the resulting drop-down list, choose Show Nonblanks. The number of rows displayed on the screen is reduced according to this specification. When you apply the same criteria to column G, what you are left with is only those rows with non-blank values in both F and G. (If you also want to check those which have nothing in both F and G, you can select Show Blanks for both column F and G.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10628) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Finding Rows with Values in Two Columns.

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

Changing the Office Assistant

How to change the Office Assistant character in Word.

Discover More

Adding a Drop Shadow to a Text Box

One way to make your text boxes "stand off" the page is to add a drop shadow to them. This tip shows just how easy it is ...

Discover More

Undoing Smart Tag Exclusions

Depending on who you ask, Smart Tags can be really cool or really distracting. If you fall on the "cool" side, you may ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (menu)

Changing AutoFilter Drop-Down Arrow Colors

The drop-down arrow used at the top of columns by AutoFilter can be difficult to see. Here's a way you can reduce the ...

Discover More

Limits to Filtering

Excel limits the number of items that can be shown in an AutoFilter drop-down list. Granted, it is a high limit, but it ...

Discover More

Setting Up Custom AutoFiltering

The filtering capabilities of Excel are very helpful when you are working with large sets of data. You can create a ...

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 six minus 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.