How to Count Cells by Header Prefix and Cell Value in Excel
Question details
The user needs to count the number of cells containing a specific value, but only within columns where the header starts with a specific character or prefix.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Counting specific data points across multiple columns filtered conditionally by their header names.
- Observed behavior
- The user wants to apply a conditional count based on two criteria simultaneously: the header's prefix string and the cell's exact value.
Ensure your data is organized in a tabular format with clear headers in the top row. Verify that there are no merged cells within your target data range or header row, as this will cause formula dimensions to mismatch.
Use SUMPRODUCT and LEFT Functions
Combine the SUMPRODUCT and LEFT functions to evaluate both the column headers and cell contents simultaneously.
The SUMPRODUCT function handles arrays without requiring special keystrokes like Ctrl+Shift+Enter. By combining it with LEFT, we can extract the first character of the headers and check it against our prefix criteria while matching the actual cell values.
Click on an empty cell where you want the final count to be displayed.
Type the formula =SUMPRODUCT(($A$2:$F$8="x")*(LEFT($A$1:$F$1,1)="A")). Replace $A$2:$F$8 with your data range, "x" with the target cell value, $A$1:$F$1 with your header row, and "A" with your desired header prefix.
Press Enter to calculate the total count of cells that meet both the header prefix and cell value conditions.

Count Cells and Manage Data Effortlessly with WPS Office
WPS Spreadsheet fully supports advanced array functions like SUMPRODUCT and LEFT. You can execute complex data analysis, filtering, and conditional counting using the same familiar formulas you use in Excel, completely for free.
- 1. Open your dataset: Launch WPS Spreadsheet and open your existing .xlsx file containing the dataset.
- 2. Select the output cell: Click on the specific cell where you want to display the conditional count result.
- 3. Enter the formula: Type the =SUMPRODUCT() formula incorporating your header and cell value conditions into the formula bar.
- 4. Get instant results: Press Enter to instantly execute the calculation and get your precise data count.

Frequently Asked Questions
Can I count based on the entire header name instead of just the prefix?
Yes, you can drop the LEFT function and simply use ($A$1:$F$1="TargetName") inside the SUMPRODUCT formula to match exact header names instead of prefixes.
Why is my SUMPRODUCT formula returning a #VALUE error?
This error usually occurs when the dimensions of your arrays do not match. Ensure your header range (e.g., A1:F1) spans the exact same number of columns as your data range (e.g., A2:F8).
Does this formula differentiate between uppercase and lowercase letters?
No, standard exact matches using the equals (=) operator in SUMPRODUCT are not case-sensitive. To make your count case-sensitive, you need to incorporate the EXACT function, like EXACT(LEFT($A$1:$F$1,1), "A").
Can I count cells containing part of a text string instead of the exact value?
Yes. You can use the ISNUMBER and SEARCH functions within the SUMPRODUCT array to find partial matches in the cell values. For example, replace ($A$2:$F$8="x") with ISNUMBER(SEARCH("x", $A$2:$F$8)).




