This post is to guide you how to count or fill the numbering of a list in Excel.
Bài viết này mình sẽ hướng dẫn các bạn cách đếm hoặc điền số thứ tự cho một danh sách trong Excel.
#1: Filling with COUNTA Function
Imagine we have an employee list, as shown in the accompanying image. Our objective is to sequentially number each employee, ensuring that the numbering won’t be filled in an blank row.
Giả sử chúng ta có một danh sách nhân sự của một công ty như hình bên dưới. Mục tiêu là điền số thứ tự cho mỗi thành viên, đảm bảo rằng số thứ tự sẽ không được điền vào ở những hàng trống.

Given the aggregated employee roster, categorized by department, conventional data entry methods such as manual fill or series fill will not facilitate the required input.
Với danh sách tổng số nhân viên trong công ty được chia theo từng phòng ban, những cách fill thông thường như handle fill, series fill sẽ không giúp gì được cho chúng ta.
To populate data in this manner, we’ll leverage the COUNTA function. This function will count the number of non-empty cells. We’ll initiate the count from cell B2.
Additionally, we’ll integrate the IF function with ISBLANK to validate cells for emptiness. If a cell is empty, it will be excluded from the count. Crucially, when constructing the formula as COUNTA(B2:B2), we must ensure that upon dragging the formula down, the first B2 (before the colon) is absolutely referenced (e.g., $B$2:B2). This fixes its position.
Conversely, the second B2 (after the colon) should remain relatively referenced, allowing it to automatically increment to B3, B4, B5, and so on. This configuration ensures that COUNTA consistently counts from the fixed B2 down to the current row.
Để điền dữ liệu kiểu này, mình sẽ dùng hàm COUNTA. Hàm này sẽ đếm xem có bao nhiêu ô đã có dữ liệu. Chúng ta sẽ bắt đầu đếm từ ô B2.
Ngoài ra, mình cần dùng thêm hàm IF kết hợp với ISBLANK để kiểm tra các ô xem có trống không. Nếu trống thì sẽ bỏ qua, không đếm.
Quan trọng nhất là khi mình viết công thức COUNTA(B2:B2), mình phải làm thế nào để khi kéo công thức xuống các ô bên dưới, ô B2 đầu tiên (trước dấu hai chấm) sẽ được cố định lại (không thay đổi), còn ô B2 thứ hai (sau dấu hai chấm) thì sẽ tự động thay đổi thành B3, B4, B5… Điều này giúp cho hàm COUNTA luôn đếm từ ô B2 đến ô hiện tại.

#2: Filling with COUNTIF Function
In contrast to the prior scenario, our current objective is to sequentially number each employee within their respective department, with the numbering automatically resetting upon the commencement of a new department.
Ngược lại với ví dụ ở trên, mục tiêu của phần này là đánh số thứ tự cho mỗi thành viên trong mỗi phòng ban, đảm bảo rằng số thứ tự sẽ tự động trở về 1 khi sang phòng ban mới.

Here’s a technical explanation of the Excel formula=IF(ISBLANK(B2),"",COUNTIF($A$2:A2,A2)):
• If B2 is blank, the formula returns an empty string (“”).
• If B2 is not blank, the formula proceeds to count. It utilizes the COUNTIF function to count occurrences of the value in cell A2 (representing the current department) within the dynamic range $A$2:A2. The absolute reference ($A$2) ensures the starting point for counting remains fixed at A2, while the relative reference (A2) automatically adjusts as the formula is copied down, expanding the range to $A$2:A3, $A$2:A4, and so on.
Hàm này hoạt động như sau:
• Đầu tiên, nó sẽ kiểm tra ô B2 xem có bị trống không.
• Nếu ô B2 KHÔNG trống, thì công thức sẽ bắt đầu đếm. Nó sẽ đếm xem giá trị trong ô A2 (tức là giá trị hiện tại của phòng ban) đã xuất hiện bao nhiêu lần trong phạm vi từ ô A2 đến ô hiện tại bạn đang đặt công thức. Nếu ô B2 trống, thì công thức này sẽ trả về một ô trống (không hiện gì cả).

Good luck!