logo
search
Formula Errors

How to Fix #VALUE! Error in Excel COUNTIF When Counting Text

Huda QurayshiHuda Qurayshi Oct 19, 2026 869 views

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.

How to Fix the #VALUE! Error in Excel COUNTIF When Counting 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.
Before you start

Verify that your COUNTIF formula syntax is correct, checking that sheet names are accurate and text criteria are enclosed in double quotation marks.

Solution 1Recommended

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.

1
Insert a helper column

Create a new blank column directly next to the range containing your text data.

2
Apply the cleaning formula

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.

3
Copy the formula down

Drag the fill handle down to apply this formula to all cells in the helper column.

4
Replace original data

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.

Clean Hidden Characters with Helper Formulas
Tip: Using Paste as Values is crucial to remove the dependency on the helper column, allowing you to safely delete it afterward.
Advanced Formula Support

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. 1. Open your dataset: Launch WPS Spreadsheet and open your workbook containing the data.
  2. 2. Clean text data: Use the Data > Text to Columns feature to quickly format your target range strictly as text.
  3. 3. Apply COUNTIF: Enter your COUNTIF formula using the intuitive formula prompts to ensure perfect syntax.
  4. 4. Verify results: Press Enter to instantly view your accurate text count without any #VALUE! errors.
100% compatibility with Microsoft Excel formulas, functions, and .xlsx files.Built-in data cleaning tools like Text to Columns and duplicate removal.Free, lightweight, and fast performance for large datasets.Intuitive interface that makes troubleshooting formula errors simple.
microsoft office alternative - wps office

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.