Count a Dynamic Department Column in Excel with MATCH and COUNTA
Question details
Count populated subdepartment cells in the column associated with a selected department ID.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Department IDs are column headers, and a selected ID determines which subdepartment column to count.
- Observed behavior
- The count should update when the selected department ID or the cells in its matching column change.
Confirm that department IDs are in Sheet1!A1:D1 and subdepartment values are in rows 2 through 100. Enter the department ID to look up in C1 on a separate summary sheet.
Count the Matching Department Column with COUNTA and MATCH
Use this formula when the selected department ID identifies a column header on Sheet1.
MATCH finds the position of the selected ID in the header range. ADDRESS and INDIRECT turn that position into a range for COUNTA to count.
On the summary sheet, enter a department ID in cell C1 that exactly matches a header in Sheet1!A1:D1.
Select a result cell outside Sheet1!A2:D100 and enter =COUNTA(INDIRECT("'Sheet1'!"&ADDRESS(2,MATCH(C1,Sheet1!$A$1:$D$1,0))&":"&ADDRESS(100,MATCH(C1,Sheet1!$A$1:$D$1,0)))).
Press Enter, then change the ID in C1 to another header to verify that the count follows the selected department.

Count Department Values Dynamically in WPS Spreadsheets
Use MATCH, ADDRESS, INDIRECT, and COUNTA in WPS Spreadsheets to count the column for a selected department ID.
- 1. Open the workbook: In WPS Spreadsheets, choose Open and select the workbook containing the department data.
- 2. Enter the department ID: On a separate summary sheet, enter an ID in C1 that matches a header in Sheet1!A1:D1.
- 3. Add the counting formula: Select a result cell outside Sheet1!A2:D100 and enter =COUNTA(INDIRECT("'Sheet1'!"&ADDRESS(2,MATCH(C1,Sheet1!$A$1:$D$1,0))&":"&ADDRESS(100,MATCH(C1,Sheet1!$A$1:$D$1,0)))).
- 4. Calculate and save: Press Enter to display the count, then use File > Save to save the workbook.

Frequently Asked Questions
Why does the formula return #N/A?
MATCH returns #N/A when the value in C1 does not match a header in Sheet1!A1:D1. Check for a misspelled ID, extra spaces, or a number stored as text.
How do I count more than 100 rows?
In the formula, change 100 in ADDRESS(100,MATCH(...)) to the last row you want to include. Keep the formula result outside the counted range.
Does COUNTA count cells that look blank?
COUNTA ignores truly empty cells but counts cells containing formulas that return an empty string, as well as other nonempty values.
Can I use a header range that starts in another column?
Yes, but adjust the column position returned by MATCH before passing it to ADDRESS. For example, add 1 to MATCH if the header range starts in column B.




