Function Problems

Count Attendance Codes with IF and COUNTIF in Excel

Chanuka GeekiyanageChanuka Geekiyanage Dec 2, 2026 868 views

Question details

Create formulas that count selected attendance or punctuality codes and display a blank when there are no matches.

Count Attendance Codes with IF and COUNTIF in Excel
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.
Before you start

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.

Solution 1Recommended

Add separate COUNTIF results and hide zero totals

Use this approach to count multiple codes with standard IF and COUNTIF functions.

1
Count attendance codes

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.

2
Count punctuality codes

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.

3
Apply the formulas to other rows

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.

Add separate COUNTIF results and hide zero totals
Why the original test can fail: COUNTIF with an array of criteria returns multiple counts. Adding separate COUNTIF results gives IF one combined total to test.
Count attendance in WPS Spreadsheets

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. 1. Open the tracker: Open WPS Spreadsheets, select Open, and choose your attendance workbook.
  2. 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. 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. 4. Fill other rows: Drag the result cell's fill handle down to calculate counts for other tracker rows.
Count multiple attendance codes in a single result cellDisplay a blank instead of zero when no codes matchOpen and edit Microsoft Excel XLSX filesUse a familiar spreadsheet interface to fill formulas down rows
microsoft office alternative - wps office

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.