Formula Errors

Add or Subtract Row Values with an Excel IF Formula

John WilsonJohn Wilson Dec 2, 2026 868 views

Question details

Use an IF formula to add or subtract two values in each row and copy the calculation down the worksheet.

Add or Subtract Row Values with an Excel IF Formula
Product
Microsoft Excel
Device & OS
not provided
Scenario
Compare values in columns A and B, calculate a result in column C for each row, and optionally total the results.
Observed behavior
When the value in column A is greater than or equal to the value in column B, the formula should add them; otherwise, it should subtract the column B value from the column A value.
Before you start

Check which columns contain the two numeric values and identify the first and last data rows. The example below assumes the values are in columns A and B, starting in row 1.

Solution 1Recommended

Use an IF formula and fill it down the rows

Use this formula to calculate each row and optionally sum all results.

1
Enter the formula

Select cell C1, enter =IF(A1>=B1,A1+B1,A1-B1), and press Enter.

2
Fill down

Select C1 and drag its fill handle down through the last data row. Excel adjusts the row references automatically.

3
Total the results

To add the results from rows 1 through 684, select an empty cell and enter =SUM(C1:C684). Change 684 to your actual last data row.

Use an IF formula and fill it down the rows
Subtraction result: When A is smaller than B, A minus B produces a negative result. If your data starts on another row, adjust the formula references before filling down.
Calculate in WPS Spreadsheets

Add or Subtract Row Values in WPS Spreadsheets

Use the same IF formula in WPS Spreadsheets, fill it down your data, and sum the calculated values.

  1. 1. Open your spreadsheet: Open WPS Spreadsheets and use File > Open to select your workbook.
  2. 2. Enter the IF formula: Select C1, type =IF(A1>=B1,A1+B1,A1-B1), and press Enter.
  3. 3. Copy the formula down: Select C1 and drag the fill handle down to the last data row.
  4. 4. Sum the results: Select an empty cell and enter =SUM(C1:C684), replacing 684 with the last row of your results.
Apply an IF formula to add or subtract values across rowsOpen and edit Microsoft Excel XLSX filesFill formulas down large data rangesUse WPS Office for free
microsoft office alternative - wps office

Frequently Asked Questions

What happens if the two values are equal?

The formula adds them because the condition A1>=B1 includes equal values.

Why is the subtraction result negative?

When A1 is smaller than B1, the formula calculates A1-B1, which is negative. Use B1-A1 in the final part of the formula if you want the positive difference instead.

How do I use the formula when my data starts on row 2?

Enter =IF(A2>=B2,A2+B2,A2-B2) in C2, then drag the fill handle down to the last data row.

How do I total the calculated values?

In an empty cell, enter a SUM formula for the result range, such as =SUM(C1:C684). Adjust the range to match your data.