
Bạn có thể giải thích "tự động" cụ thể nghĩa là khi nào thì nhập?Anh chị Giúp tôi code điền số thứ tự tự động, tôi gửi File kèm mong anh chị giúp, cảm ơn nhiều.



Cảm ơn bạn, mình muốn thực hiện bằng code bạn ơi.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i, j, currentrow As Integer
    If Target.Column = 2 Then
        currentrow = Target.Row
        For i = 2 To currentrow
        If Cells(i, 2) <> Cells(i - 1, 2) Then
            For j = i - 1 To 1 Step -1
                If Cells(j, 1) <> "" Then
                    Cells(i, 1) = Cells(j, 1) + 1
                    GoTo 1
                End If
            Next
        End If
1:
    Next
    End If
    
End Sub
	Nếu format thì lúc mail merge chẳng hạn nó lại hiển thị là 1; 2; 3 ... bác ạCái này thuộc về format thui mà. Chọn cột vào format chọn custom đánh 00



code này vậyNếu format thì lúc mail merge chẳng hạn nó lại hiển thị là 1; 2; 3 ... bác ạ
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i, j, lastrow, dem As Integer
dem = 1
    If Target.Column = 2 Then
        Cells(1, 1) = "'01"
        lastrow = Range("B" & Rows.Count).End(3).Row
        If lastrow > 1 Then Range("A2:A" & lastrow).Clear
        For i = 2 To lastrow
            If Cells(i, 2) <> Cells(i - 1, 2) Then
                dem = dem + 1
                Cells(i, 1) = "'" & Right("00" & dem, 2)
            End If
        Next
    End If
End Sub
	Cảm ơn bác rất nhiều, em có bài toán này khó hơn, mong bác giúp em được không ạ, thanks nhiềucode này vậy
Mã:Private Sub Worksheet_Change(ByVal Target As Range) Dim i, j, lastrow, dem As Integer dem = 1 If Target.Column = 2 Then Cells(1, 1) = "'01" lastrow = Range("B" & Rows.Count).End(3).Row If lastrow > 1 Then Range("A2:A" & lastrow).Clear For i = 2 To lastrow If Cells(i, 2) <> Cells(i - 1, 2) Then dem = dem + 1 Cells(i, 1) = "'" & Right("00" & dem, 2) End If Next End If End Sub




Thì đâyCảm ơn bác rất nhiều, em có bài toán này khó hơn, mong bác giúp em được không ạ, thanks nhiều![]()
Sub run()
Dim i, dem As Integer
    For i = 7 To Range("C6000").End(3).Row
        If Cells(i, 2) = "HM" Then dem = 0
        If Cells(i, 3) <> "" And Cells(i, 2) <> "HM" Then
            dem = dem + 1
            Cells(i, 1) = "'" & Right("00" & dem, 2)
        End If
    Next
End Sub
	Híc, nó chạy được nhưng phải gán nút bác ạ, em muốn tự động có được khôngThì đây
Mã:Sub run() Dim i, dem As Integer For i = 7 To Range("C6000").End(3).Row If Cells(i, 2) = "HM" Then dem = 0 If Cells(i, 3) <> "" And Cells(i, 2) <> "HM" Then dem = dem + 1 Cells(i, 1) = "'" & Right("00" & dem, 2) End If Next End Sub



Dữ liệu của bạn nhiều??? Có gì đâu mà treo dc nhỉ?Em đã sửa tên thành Private Sub Worksheet_Change(ByVal Target As Range) để tự động chạy nhưng được khoảng vài dòng thì máy bị treo bác ạ
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i, dem As Integer
If Target.Column = 2 Or Target.Column = 3 Then
    Range("A7:A1000").ClearContents
    For i = 7 To Range("C6000").End(3).Row
        If Cells(i, 2) = "HM" Then dem = 0
        If Cells(i, 3) <> "" And Cells(i, 2) <> "HM" Then
            dem = dem + 1
            Cells(i, 1) = "'" & Right("00" & dem, 2)
        End If
    Next
End If
End Sub
	Làm phiền bác quanluu tý. Với code này giờ em lại muốn gán nút thì sửa thế nào ạ,Dữ liệu của bạn nhiều??? Có gì đâu mà treo dc nhỉ?
Mã:Private Sub Worksheet_Change(ByVal Target As Range) Dim i, dem As Integer If Target.Column = 2 Or Target.Column = 3 Then Range("A7:A1000").ClearContents For i = 7 To Range("C6000").End(3).Row If Cells(i, 2) = "HM" Then dem = 0 If Cells(i, 3) <> "" And Cells(i, 2) <> "HM" Then dem = dem + 1 Cells(i, 1) = "'" & Right("00" & dem, 2) End If Next End If End Sub