Count Values Under a Selected Column Header in Excel
Question details
Count occurrences of a value under the column header matching a selected name.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Names appear across column headers, dates run down rows, and a reporting cell contains the name to match.
- Observed behavior
- The desired formula counts cells containing W in columns whose header matches the selected name.
Identify the header row, the data range beneath it, and the cell containing the selected name. Make sure the header and data ranges cover the same columns.
Use SUMPRODUCT to count values under a matching header
Use this formula when the headers, data, and selected name are on the same worksheet.
Enter the name to match in cell A6. This example uses headers in A1:C1 and data in A2:C4.
Select an empty result cell and enter =SUMPRODUCT(($A$1:$C$1=A6)*($A$2:$C$4="W")), then press Enter.
In the formula bar, replace A1:C1 and A2:C4 with your header and data ranges, and replace A6 or "W" if your name cell or target value differs.
Count matching values from another worksheet
Use sheet-qualified ranges when the source data and report are on different worksheets.
Count values under matching headers in WPS Spreadsheets
Use SUMPRODUCT in WPS Spreadsheets to match a selected name against column headers and count the corresponding W values.
- 1. Open the workbook: Open WPS Office, choose Spreadsheets, and open the workbook containing your headers and data.
- 2. Enter the name: Enter the selected name in A6, assuming the headers are in A1:C1 and the data is in A2:C4.
- 3. Add the formula: Select an empty cell and enter =SUMPRODUCT(($A$1:$C$1=A6)*($A$2:$C$4="W")), then press Enter.
- 4. Save the result: Check the count and use File > Save to save the workbook.

Frequently Asked Questions
Can I count a value other than W?
Yes. Replace "W" in the formula with the value you want to count, such as "P".
How do I use a sheet name that contains spaces?
Enclose the sheet name in single quotes in each range reference, for example, 'Data Sheet'!$A$1:$C$1.
What happens if more than one column has the selected name?
SUMPRODUCT counts matching values under every column whose header matches the name in A6.
Do I need to use a special array-entry shortcut?
No. Enter the SUMPRODUCT formula in the result cell and press Enter.




