How to Count Cells Containing H or S in Excel
Question details
The user needs to count specific cells containing the text 'H' or 'S' while ignoring blanks or other characters.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Analyzing worksheet data that includes multiple specific text values, requiring a count of cells that match one of several given criteria.
- Observed behavior
- The user wants to evaluate a specific range of cells and return the total count of cells that exactly match either 'H' or 'S'.
Identify the exact range of cells you want to evaluate and ensure there are no hidden trailing spaces in the cells containing 'H' or 'S', as extra spaces can prevent the formula from recognizing the text.
Use Multiple COUNTIF Functions
The most straightforward method is to use the COUNTIF function twice (once for each text criteria) and add the results together.
This method is simple to understand and works perfectly when you only have a few specific text values to count.
Click on the empty cell where you want the final count to be displayed.
Type the formula =COUNTIF(A1:A10,"H")+COUNTIF(A1:A10,"S") into the formula bar. Replace A1:A10 with the actual range containing your data.
Press the Enter key. The cell will now display the total combined number of cells containing exactly 'H' or 'S'.

Use SUM and COUNTIF with an Array Constant
For a more compact formula, you can use an array constant inside the COUNTIF function wrapped with SUM.
Count Data Easily with WPS Spreadsheet
You can perform all advanced data counting tasks, including COUNTIF and array formulas, directly in WPS Spreadsheet. It offers a familiar interface and comprehensive function support for all your data analysis needs.
- 1. Open your file in WPS Spreadsheet: Launch WPS Office and open the spreadsheet document containing the data you want to count.
- 2. Apply the counting formula: Select a blank cell and input the exact same formula you use in Excel: =SUM(COUNTIF(A1:A10,{"H","S"})).
- 3. Press Enter to calculate: Hit Enter to instantly view the counted cells. WPS Spreadsheet seamlessly handles array constants and standard Excel functions.

Frequently Asked Questions
Why is my COUNTIF formula returning 0?
This usually happens if the target cells contain hidden characters or trailing spaces. You can use the TRIM function in a helper column to clean your data first, or check if your selected cell range in the formula is correct.
Can I count more than two specific texts using this method?
Yes. With the array method, you can easily add more criteria inside the curly brackets. For example, to count H, S, and X, you would use =SUM(COUNTIF(A1:A10,{"H","S","X"})).
Are these counting formulas case-sensitive?
No, the COUNTIF function is not case-sensitive. It will count 'H' and 'h' as the same character. If you require strict case-sensitive counting, you must use a combination of the SUMPRODUCT and EXACT functions, such as =SUMPRODUCT(--(EXACT(A1:A10,"H"))).




