Count Attendance Codes with IF and COUNTIF in Excel
Question details
Create formulas that count selected attendance or punctuality codes and display a blank when there are no matches.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A monthly attendance tracker contains codes across a row, and the user needs separate totals for attendance and punctuality conditions.
- Observed behavior
- The existing formula does not return the correct combined count for A and NCNS.
Check that the tracker sheet is named Attendance and that C3:IU3 covers the cells you want to count. Adjust the sheet name or range in the formulas if your layout differs.
Add separate COUNTIF results and hide zero totals
Use this approach to count multiple codes with standard IF and COUNTIF functions.
Select an empty result cell outside the counted range and enter =IF(COUNTIF(Attendance!C3:IU3,"A")+COUNTIF(Attendance!C3:IU3,"NCNS")=0,"",COUNTIF(Attendance!C3:IU3,"A")+COUNTIF(Attendance!C3:IU3,"NCNS")), then press Enter.
Select another empty result cell and enter =IF(COUNTIF(Attendance!C3:IU3,"L")+COUNTIF(Attendance!C3:IU3,"OB")+COUNTIF(Attendance!C3:IU3,"UT")=0,"",COUNTIF(Attendance!C3:IU3,"L")+COUNTIF(Attendance!C3:IU3,"OB")+COUNTIF(Attendance!C3:IU3,"UT")), then press Enter.
Select each result cell and drag its fill handle down to calculate totals for other rows. Check that the row references change to match each person's tracker row.

Use LET to shorten the punctuality formula in Microsoft 365
Use LET and an array of criteria to calculate the total once in Microsoft 365.
Count attendance codes in WPS Spreadsheets
Open your tracker in WPS Spreadsheets and use IF and COUNTIF to total attendance codes while leaving zero-match results blank.
- 1. Open the tracker: Open WPS Spreadsheets, select Open, and choose your attendance workbook.
- 2. Check the range: Select the Attendance sheet and confirm that C3:IU3 contains the codes to count. Adjust the formula range if needed.
- 3. Enter the formula: Select an empty cell outside the counted range and enter =IF(COUNTIF(Attendance!C3:IU3,"A")+COUNTIF(Attendance!C3:IU3,"NCNS")=0,"",COUNTIF(Attendance!C3:IU3,"A")+COUNTIF(Attendance!C3:IU3,"NCNS")), then press Enter.
- 4. Fill other rows: Drag the result cell's fill handle down to calculate counts for other tracker rows.

Frequently Asked Questions
Why does the formula show a blank instead of zero?
The IF function tests whether the combined COUNTIF total is zero. If it is, the formula returns an empty string, "".
How do I count a different set of attendance codes?
Edit the formula in the formula bar and replace the quoted criteria, such as "A" and "NCNS", with your codes. Add another COUNTIF term in both the test and the result for each additional code.
Does COUNTIF distinguish between uppercase and lowercase codes?
No. COUNTIF is not case-sensitive, so the criterion "A" also matches a cell containing "a".
Why might a code not be counted?
Check that the cell is within the referenced range and that its value matches the criterion. Extra spaces in a cell can prevent an exact code match.




