Sum Two Excel Cells Only When Neither Is Zero
Question details
Add X16 and Y16 only when both cells are nonzero; otherwise, return zero.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet needs a conditional sum of two cells.
- Observed behavior
- The desired result is the sum when neither cell is zero, or zero when either cell is zero.
Check that X16 and Y16 contain numeric values, and choose a different cell, such as Z16, for the result.
Use IF and OR to test both cells before adding
Use this formula when either zero value should make the result zero.
In the worksheet, click an empty cell such as Z16.
Type =IF(OR(X16=0,Y16=0),0,X16+Y16) in the cell or formula bar, and press Enter.
Enter nonzero numbers in X16 and Y16 to see their sum, then change either value to 0 to confirm that the result becomes 0.

Calculate the same conditional sum in WPS Spreadsheets
Use IF and OR in WPS Spreadsheets to add X16 and Y16 only when both are nonzero.
- 1. Open your workbook: Open WPS Spreadsheets and choose Open to select your Excel workbook.
- 2. Select an empty cell: Click Z16 or another cell outside X16 and Y16.
- 3. Enter the formula: Type =IF(OR(X16=0,Y16=0),0,X16+Y16) and press Enter.
- 4. Save the workbook: Choose Menu > Save or Save As to save your changes.

Frequently Asked Questions
What happens if one of the cells is blank?
The formula treats a blank referenced cell as zero in the comparison and returns 0.
Will the formula work with negative numbers?
Yes. Negative numbers are nonzero, so the formula adds them as long as neither cell equals zero.
How can I apply the formula to other rows?
Select the formula cell and drag its fill handle down. Excel adjusts the relative references for each row.
Can I use a SUM formula instead?
Yes. Enter =SUM(X16:Y16)*NOT(COUNTIFS(X16:Y16,0)) in a separate result cell to return the sum when neither cell equals zero.




