Sub TaoMaHSTheoKhoi()
Dim Rws As Long, J As Long, Dm As Integer
Dim Lop As String
Lop = "6"
Rws = [B6].CurrentRegion.Rows.Count
For J = 7 To Rws + 7
If Cells(J, "C").Value = "" Then Exit For
If Lop = Left(Cells(J, "E").Value, 1) Then
Dm = Dm + 1
Cells(J, "B").Value = Lop & Right("00" & CStr(Dm), 3)
Else
Lop = Left(Cells(J, "E").Value, 1)
Cells(J, "B").Value = Lop & "001"
Dm = 1
End If
Next J
End Sub
Sub TaoMaHSTheoKhoiCuaNam()
Const Alf As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim Rws As Long, J As Long, Dm As Integer
Dim Lop As String, Nm As String
Nm = Mid(Alf, Year(Date) - 2010, 1)
Lop = Nm & "6"
Rws = [B6].CurrentRegion.Rows.Count
For J = 7 To Rws + 7
If Cells(J, "C").Value = "" Then Exit For
If Right(Lop, 1) = Left(Cells(J, "E").Value, 1) Then
Dm = Dm + 1
Cells(J, "B").Value = Lop & Right("00" & CStr(Dm), 3)
Else
Lop = Nm & Left(Cells(J, "E").Value, 1)
Cells(J, "B").Value = Lop & "001"
Dm = 1
End If
Next J
End Sub
Thử công thức này:Các bạn giúp mình tạo 1 mã học sinh theo từng khối lớp, ví dụ: Lớp đầu tiên 6a1; học sinh có số thứ tự số 1 có mã 6001;
em tiếp theo có mã 6002...Lớp 7a1 em đầu tiên có mã là 7001 tương tự như trên..Mong các bạn giúp dùm mình nhe