Function Problems

Excel: Add Two Cells Only When Both Are Nonblank

Anum MushtaqAnum Mushtaq Dec 2, 2026 868 views

Question details

Return the sum of two input cells only when both contain values; otherwise, display a blank result.

Add Two Excel Cells Only When Both Are Nonblank
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet needs to add two values without displaying a result until both inputs are populated.
Observed behavior
The desired formula displays the combined value when both inputs are populated and appears blank when either input is empty.
Before you start

Identify the two input cells and an empty result cell. The example below uses D2 and E2 as inputs and F2 for the formula.

Solution 1Recommended

Use IF and AND to Add Two Nonblank Cells

Use this formula when you want a result only after both input cells contain values.

1
Select the result cell

In Excel, select F2 or another cell where you want the sum to appear.

2
Enter the formula

Type =IF(AND(D2<>"",E2<>""),D2+E2,"") and press Enter. Replace D2 and E2 with your input cell references if needed.

3
Apply it to other rows

Select F2 and drag the fill handle down to copy the formula to additional rows.

Use IF and AND to Add Two Nonblank Cells
Format durations if needed: For elapsed time values, select the result cells and use Format Cells > Custom with a format such as [h]:mm. The empty-looking result contains a formula that returns an empty string.
Work with formulas in WPS

Add Nonblank Values in WPS Spreadsheets

Use the same IF and AND formula in WPS Spreadsheets to show a sum only when both input cells are populated.

  1. 1. Open your workbook: Open WPS Spreadsheets and select Open to choose your workbook.
  2. 2. Select the result cell: Click F2, assuming D2 and E2 contain the two input values.
  3. 3. Enter the formula: Type =IF(AND(D2<>"",E2<>""),D2+E2,"") and press Enter.
  4. 4. Copy the formula: Drag the fill handle from F2 down to apply the formula to other rows.
Keep the result visually blank until both input values are presentOpen and edit Microsoft Excel XLSX and XLS filesCopy the formula across multiple rows with the fill handleFormat duration results with a custom time format
microsoft office alternative - wps office

Frequently Asked Questions

Does the formula treat zero as a blank?

No. Zero is a value, so the formula includes it when both input cells are populated.

What happens if an input cell contains a formula that returns an empty string?

The comparison with "" treats that result as blank, so the result cell also displays an empty string.

Can I use SUMIFS instead of IF and AND?

SUMIFS is designed to sum ranges based on criteria. For adding two individual cells only when both are populated, =IF(AND(D2<>"",E2<>""),D2+E2,"") is more direct.

Why does the formula return an error when both cells are populated?

The formula adds D2 and E2 directly, so nonnumeric text can cause a #VALUE! error. Check the input cells and replace text with numeric values where appropriate.