How to Use Excel Formulas to Compare Two Cells and Show the Difference
Question details
The user needs to compare the numerical values of two cells (A3 and B3) and output the difference in separate columns based on which cell's value is greater.

- Product
- Excel / WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- Comparing data sets, such as budget variances or inventory audits, where positive and negative differences must be segregated into distinct columns for reporting.
- Observed behavior
- The goal is to display the positive difference in C3 if A3 is greater, and the negative difference in D3 if B3 is greater, while leaving the cell blank if the condition is not met.
Ensure that the cells you are comparing contain numerical data. If the cells contain text or numbers formatted as text, the subtraction will result in a #VALUE! error.
Use the IF Function to Segregate Positive and Negative Differences
You can use a standard logical IF formula to evaluate which cell is larger and output the exact mathematical difference in the designated column while keeping the other column blank.
The IF function in spreadsheet software evaluates a logical condition and returns one value if true and another if false. By nesting the subtraction formula inside the IF function, you dictate exactly when and where the difference is calculated.
Click on cell C3. Enter the formula: =IF(A3>B3, A3-B3, ""). Press Enter. This checks if A3 is greater than B3; if true, it calculates the difference, otherwise it leaves the cell blank.
Click on cell D3. Enter the formula: =IF(B3>A3, A3-B3, ""). Press Enter. This checks if B3 is greater than A3; if true, it calculates the negative difference (since A3 is smaller), otherwise it leaves the cell blank.
Highlight both cells C3 and D3. Click and hold the small square at the bottom right corner of the selection (the fill handle), and drag it down to apply the formulas to the rest of the rows in your sheet.

Compare Data and Calculate Differences seamlessly in WPS Spreadsheet
WPS Spreadsheet fully supports advanced logical functions, including IF, nested IFs, and mathematical calculations. It offers a smooth and lightweight environment to manage complex data comparisons without lag.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open the workbook containing the data you want to compare.
- 2. Select the target cell: Click on the cell where you want the positive or negative difference to be displayed.
- 3. Enter the IF formula: Type the exact same formula (e.g., =IF(A3>B3, A3-B3, "")) directly into the formula bar and press Enter.
- 4. Drag to fill: Use the smart fill handle in WPS Spreadsheet to drag the formula down your column instantly.

Frequently Asked Questions
Why does my formula return a #VALUE! error instead of the difference?
This error occurs when one or both of the cells being compared contain text, hidden spaces, or special characters instead of pure numbers. Check the values in A3 and B3, remove any trailing spaces, and ensure the cells are formatted as 'Number' or 'General'.
Can I display a zero instead of a blank cell when the values are equal?
Yes. If you prefer to show a zero rather than an empty cell, replace the empty quotation marks ("") at the end of your formula with a 0. For example, your formula in C3 would become: =IF(A3>B3, A3-B3, 0).
How can I compare cells across different sheets or workbooks?
You can reference cells in other sheets by including the sheet name followed by an exclamation mark before the cell reference. For example: =IF(Sheet1!A3>Sheet2!B3, Sheet1!A3-Sheet2!B3, ""). In WPS Spreadsheet, you can also simply click the target cells across sheets while typing the formula to automatically generate the correct reference.




