The goal is to verify the input of all required values before calculating a result. In the worksheet shown, the SUM function is used as an example only. You can use the same approach with any formula to prevent calculation until all required values are available. The logic can be adjusted in many ways to suit the situation. Below are several examples of how you can approach this problem. The best solution depends on the requirements of the project and your personal preference.
IF + COUNT
In the example shown, we are using the IF function together with the COUNT function:
Translation: if the count of numbers in C5:C7 is 3, sum the range C5:C7. Otherwise, display nothing.
The logical test is based on the COUNT function, which counts numeric values:
COUNT(C5:C7)=3 // returns TRUE or FALSE
This test will return FALSE until the range C5:C7 contains three numbers. This will cause the IF function to return the value_if_false, which has been supplied as an empty string (""). In Excel, an empty string will look like an empty cell. Since C7 has no value in the original worksheet, the formula displays no result. Once the range C5:C7 contains three numbers, the test will return TRUE and IF will run the SUM function, which will return the sum of C5:C7 as a final result.
There are many ways to check for blank cells, and several other options are explained below.
IF + COUNTBLANK
The COUNTBLANK function counts empty cells in a range, so we can write a slightly more compact formula like this:
If COUNTBLANK returns any non-zero number, the IF function will evaluate the number as TRUE, and return an empty string (""). If COUNTBLANK returns zero, IF will evaluate zero as FALSE and return the result from the SUM function.
IF + ISBLANK
Another approach is to use the ISBLANK function. ISBLANK returns TRUE when a cell reference is empty. ISBLANK was originally designed to test one cell only, but you can use ISBLANK three times inside the OR function together like this:
OR will return TRUE if any supplied value is TRUE. In other words, the OR function will return TRUE if any of the ISBLANK functions return TRUE. Alternatively, can use a formula like this:
Note: this is an array formula and must be entered with control + shift + enter in Excel 2019 and older. In the current version of Excel, it will work fine as-is.
In this formula, we pass a range into ISBLANK and ISBLANK returns an array that contains 3 results. If any value in the array is TRUE, the OR function returns TRUE, causing IF to return an empty string (""). If all values in the array are FALSE (i.e. all three cells contain values), OR returns FALSE, and IF returns the result from SUM:
IF with logical operators
Another option is to use standard logical operators like ="" and <>"" to test for empty and non-empty cells. To test for any empty cells, use a formula like this:
To test for non-empty cells use <>"" inside the AND function like this:
In this formula, notice the SUM function has been moved to the value_if_true argument, and will only run if all 3 cells are not empty.
IF + COUNTA
Finally, you also use the COUNTA function to test for non-empty cells like this:
While the COUNT function only counts numeric values, the COUNTA function counts any kind of value (i.e. numbers or text). As long as the range C5:C5 contains three values (numbers or text), the result will be TRUE and the SUM function will run. This doesn't really make sense for the example shown (which requires numeric input) but it can be used in other situations.