Function Problems

Count a Dynamic Department Column in Excel with MATCH and COUNTA

Huda QurayshiHuda Qurayshi Nov 27, 2026 869 views

Question details

Count populated subdepartment cells in the column associated with a selected department ID.

Count a Dynamic Department Column in Excel with MATCH and COUNTA
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the department

On the summary sheet, enter a department ID in cell C1 that exactly matches a header in Sheet1!A1:D1.

2
Enter the 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)))).

3
Check the result

Press Enter, then change the ID in C1 to another header to verify that the count follows the selected department.

Count the Matching Department Column with COUNTA and MATCH
What COUNTA includes: COUNTA counts nonempty cells, including cells with formulas that return an empty string. An ID that does not match a header returns #N/A.
WPS Spreadsheets

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. 1. Open the workbook: In WPS Spreadsheets, choose Open and select the workbook containing the department data.
  2. 2. Enter the department ID: On a separate summary sheet, enter an ID in C1 that matches a header in Sheet1!A1:D1.
  3. 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. 4. Calculate and save: Press Enter to display the count, then use File > Save to save the workbook.
Update the count by changing the selected department IDUse familiar spreadsheet functions for dynamic rangesOpen and edit Microsoft Excel XLSX files
microsoft office alternative - wps office

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.