Add or Subtract Row Values with an Excel IF Formula
Question details
Use an IF formula to add or subtract two values in each row and copy the calculation down the worksheet.

- 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.
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.
Use an IF formula and fill it down the rows
Use this formula to calculate each row and optionally sum all results.
Select cell C1, enter =IF(A1>=B1,A1+B1,A1-B1), and press Enter.
Select C1 and drag its fill handle down through the last data row. Excel adjusts the row references automatically.
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.

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. Open your spreadsheet: Open WPS Spreadsheets and use File > Open to select your workbook.
- 2. Enter the IF formula: Select C1, type =IF(A1>=B1,A1+B1,A1-B1), and press Enter.
- 3. Copy the formula down: Select C1 and drag the fill handle down to the last data row.
- 4. Sum the results: Select an empty cell and enter =SUM(C1:C684), replacing 684 with the last row of your results.

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.




