Fix Incorrect COUNTIF and SUMIF Totals in Excel
Question details
The user needs to correct unexpected totals from COUNTIF and SUMIF formulas in Excel.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Counting or summing matching values in a worksheet that may contain pasted or imported data.
- Observed behavior
- COUNTIF or SUMIF returns unexpected totals when ranges, data types, spaces, or hidden characters interfere with matching.
Identify the criteria column, the cell containing the criterion, and the values to sum. Check whether the data was pasted or imported, since it may contain hidden characters or numbers stored as text.
Align the COUNTIF and SUMIF Ranges
Use matching, fixed ranges to ensure the formulas evaluate the intended rows.
Select the COUNTIF formula cell and check its range and criterion in the formula bar. For example, use =COUNTIF($A$2:$A$500,K14) to count matches for K14 in A2:A500.
Select the SUMIF formula cell and use corresponding rows for the criteria and sum ranges. For example, enter =SUMIF($A$2:$A$500,K2,$I$2:$I$500).
Copy the formula to the needed cells and inspect the formula bar to confirm that the dollar signs keep the data ranges fixed while the criterion reference changes as intended.

Clean Extra Spaces and Hidden Characters
Use this method when pasted or imported text looks identical but does not match.
Convert Numbers Stored as Text
Use this method when numeric criteria or sum values were imported as text.
Check COUNTIF and SUMIF Totals in WPS Spreadsheet
Open your workbook in WPS Spreadsheet, clean imported values, and use matching ranges to calculate counts and sums.
- 1. Open the workbook: In WPS Spreadsheet, use Open to select your Excel workbook.
- 2. Clean imported text: In an empty column, enter =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))) and fill it down. Apply the same cleanup to the criterion if needed.
- 3. Enter the formulas: In empty cells, enter =COUNTIF($A$2:$A$500,K2) and =SUMIF($A$2:$A$500,K2,$I$2:$I$500), adjusting the ranges and criterion to match your sheet.
- 4. Verify and save: Check that the criteria and sum ranges cover corresponding rows and that sum values are numeric, then use Save or Save As to save the workbook.

Frequently Asked Questions
Why does COUNTIF miss values that look identical?
The cells may contain extra spaces or hidden characters. In a helper column, use =TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," "))) and apply the same cleanup to the criterion.
Do SUMIF ranges need to be the same size?
Yes. Use criteria and sum ranges with the same dimensions and corresponding rows, such as A2:A500 and I2:I500.
Why is SUMIF ignoring some amounts?
Amounts stored as text may not be included in the sum. Test a value with =ISNUMBER(I2), then use Excel's Convert to Number warning option or =VALUE(I2) in a helper column.
Will TRIM remove nonbreaking spaces?
Not by itself. Replace nonbreaking spaces with ordinary spaces using SUBSTITUTE(A2,CHAR(160)," "), then apply TRIM to the result.




