How to Fix #VALUE! Error in Excel COUNTIF When Counting Text
Question details
The user is experiencing a #VALUE! error while using the COUNTIF formula to count text cells in an Excel worksheet, despite the cells appearing to contain valid text.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Attempting to count occurrences of specific text within a range using the COUNTIF function.
- Observed behavior
- The formula returns a #VALUE! error instead of the correct text count, often caused by hidden characters, inconsistent data formats, or syntax issues.
Verify that your COUNTIF formula syntax is correct, checking that sheet names are accurate and text criteria are enclosed in double quotation marks.
Clean Hidden Characters with Helper Formulas
Use this method if your text contains non-printable characters or non-breaking spaces that cause formula calculation failures.
Often, data imported from other systems includes hidden characters like non-breaking spaces (CHAR(160)) that standard formatting cannot remove. Combining TRIM, CLEAN, and SUBSTITUTE ensures all extraneous characters are stripped out.
Create a new blank column directly next to the range containing your text data.
In the first cell of the new column, enter the formula =TRIM(CLEAN(SUBSTITUTE(C2,CHAR(160)," "))) (adjusting C2 to your starting cell) and press Enter.
Drag the fill handle down to apply this formula to all cells in the helper column.
Copy the entire helper column, right-click the original data range, and select Paste as Values to overwrite the corrupted text with the clean text.

Convert Values Using Text to Columns
This solution forces Excel to recognize the data strictly as text, resolving inconsistent data type issues.
Verify and Correct the COUNTIF Syntax
Apply this check to ensure the formula parameters, references, and criteria formats are perfectly structured.
Fix Data Errors and Run COUNTIF Smoothly with WPS Spreadsheet
WPS Spreadsheet provides robust data handling capabilities, allowing you to seamlessly clean text, fix formatting issues, and calculate complex formulas without encountering the #VALUE! error.
- 1. Open your dataset: Launch WPS Spreadsheet and open your workbook containing the data.
- 2. Clean text data: Use the Data > Text to Columns feature to quickly format your target range strictly as text.
- 3. Apply COUNTIF: Enter your COUNTIF formula using the intuitive formula prompts to ensure perfect syntax.
- 4. Verify results: Press Enter to instantly view your accurate text count without any #VALUE! errors.

Frequently Asked Questions
Why does COUNTIF return a #VALUE! error when referencing another workbook?
The COUNTIF function requires the referenced external workbook to remain open in the background. If the external file is closed, the formula cannot calculate the range and will result in a #VALUE! error. You can fix this by keeping the file open or using the SUMPRODUCT function instead.
How do I know if my cells have hidden characters causing formula errors?
You can test a cell using the LEN function (e.g., =LEN(C2)). If the returned character count is higher than the visible letters, the cell contains hidden spaces or non-printable characters. You should use the TRIM or CLEAN functions to remove them.
Does COUNTIF differentiate between uppercase and lowercase text?
No, COUNTIF is not case-sensitive. It will count 'Data' and 'data' as identical values. If you need a case-sensitive count, you should use a combination of the SUMPRODUCT and EXACT functions.




