How to Use Excel IF Formula to Ignore Blank Cells with AND Logic
Question details
The user needs a formula to evaluate a range of cells, returning a blank result if the entire range is empty, and checking if all non-blank cells match a specific value (e.g., 'P') to return 'PASS' or 'FAIL'.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating a logical test in a spreadsheet where blank cells should be ignored during evaluation, but fully empty rows should not trigger a PASS or FAIL result.
- Observed behavior
- Standard IF and AND formulas might incorrectly evaluate blank cells as fails or zeros, leading to inaccurate status reporting for incomplete rows.
Identify the exact range of cells you want to evaluate and determine the specific text or value (such as 'P') that constitutes your passing criteria.
Use a Nested IF Formula with COUNTA and COUNTIFS
This is the most robust method to ensure fully blank ranges return a blank cell, while selectively ignoring blanks when validating specific text criteria.
By combining COUNTA (to check for completely empty rows) and COUNTIFS (to check for failing conditions while excluding blanks), you create a reliable evaluation logic.
Click on the cell where you want the PASS/FAIL result to appear.
Enter the formula =IF(COUNTA(J27:U27)=0,"",IF(COUNTIFS(J27:U27,"<>P",J27:U27,"<>")>0,"FAIL","PASS")) into the formula bar. Replace J27:U27 with your actual range and P with your target value.
Press Enter. The formula first checks if the range is completely empty using COUNTA. If true, it returns a blank string. If not empty, it counts cells that do not equal 'P' and are not blank. If this count is greater than 0, it returns 'FAIL'; otherwise, 'PASS'.

Use an Alternative Formula with COUNTIF and COUNTBLANK
Another approach is to compare the total number of non-blank cells against the count of cells exactly matching your target criteria.
Easily Manage Complex Formulas with WPS Office
WPS Office Spreadsheet provides full support for advanced logical formulas like IF, COUNTIFS, and COUNTA, making it easy to analyze your data without compatibility issues.
- 1. Open your spreadsheet: Launch WPS Office and open your workbook containing the data to be evaluated.
- 2. Input your logic: Select the cell for your evaluation result and type your nested IF formula using the built-in formula suggestions.
- 3. Auto-fill your data: Use the drag handle at the bottom-right corner of the cell to copy the formula down your column instantly.

Frequently Asked Questions
Why does my standard IF(AND()) formula fail when there are blank cells?
The standard AND() function evaluates every cell referenced in the range. If a cell is blank, the software may treat it as a 0 or FALSE, causing the entire AND statement to return FALSE. Using COUNTIFS avoids this by explicitly excluding blanks from the evaluation.
Can I check for multiple passing values instead of just 'P'?
Yes, but you will need to adjust the COUNTIFS criteria or use an array formula (like SUMPRODUCT) to allow for multiple acceptable values before triggering a 'FAIL'.
How do I apply this formula to an entire column without retyping it?
After entering the formula in the first row of your target column, click the small square at the bottom-right of the cell (the fill handle) and drag it down, or simply double-click it to auto-fill the formula to the bottom of your dataset.




