giúp e sửa code vba với ạ.

Liên hệ QC
Tôi tuân thủ nội quy khi đăng bài

bhtrong2808

Thành viên mới
Tham gia
18/9/23
Bài viết
13
Được thích
-2
tình hình là em có code như thế này ạ( ko phải em làm);


Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("E:E")) Is Nothing Then
Application.EnableEvents = False
If Target.Offset(0, -2).Value = "" Then
Target.Offset(0, -2).Value = Now
End If
If Target.Offset(0, -1).Value = "" Then
Target.Offset(0, -1).Value = Now
End If
Application.EnableEvents = True
End If
End Sub



mỗi khi e chèn thêm 1 hàng thì code sẽ báo lỗi
Run-time error "1004"
Application-defined or object-defined error.
M.N GIÚP E VỚI Ạ
 
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rE As Range
    Set rE = Application.Intersect(Target, Range("E:E"))
    If Not rE Is Nothing Then
        If rE.Areas.Count = 1 And rE.CountLarge = 1 Then
            On Error Resume Next
            Application.EnableEvents = False
            If Range("C" & rE.Row).Value = "" Then
                 Range("C" & rE.Row).Value = Now
            End If
            If Range("D" & rE.Row).Value = "" Then
                 Range("D" & rE.Row).Value = Now
            End If
            Application.EnableEvents = True
            On Error Resume Next
        End If
    End If
End Sub

Bạn thử code này xem, đủ đáp ứng các yêu cầu cơ bản.
 
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rE As Range
    Set rE = Application.Intersect(Target, Range("E:E"))
    If Not rE Is Nothing Then
        If rE.Areas.Count = 1 And rE.CountLarge = 1 Then
            On Error Resume Next
            Application.EnableEvents = False
            If Range("C" & rE.Row).Value = "" Then
                 Range("C" & rE.Row).Value = Now
            End If
            If Range("D" & rE.Row).Value = "" Then
                 Range("D" & rE.Row).Value = Now
            End If
            Application.EnableEvents = True
            On Error Resume Next
        End If
    End If
End Sub

Bạn thử code này xem, đủ đáp ứng các yêu cầu cơ bản.
Em cảm ơn nhé ạ. Để sáng mai e test thử. Hihi
 
Mã:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rE As Range
    Set rE = Application.Intersect(Target, Range("E:E"))
    If Not rE Is Nothing Then
        If rE.Areas.Count = 1 And rE.CountLarge = 1 Then
            On Error Resume Next
            Application.EnableEvents = False
            If Range("C" & rE.Row).Value = "" Then
                 Range("C" & rE.Row).Value = Now
            End If
            If Range("D" & rE.Row).Value = "" Then
                 Range("D" & rE.Row).Value = Now
            End If
            Application.EnableEvents = True
            On Error Resume Next
        End If
    End If
End Sub

Bạn thử code này xem, đủ đáp ứng các yêu cầu cơ bản.
code giúp e chạy bt được nhưng khi e chèn thêm dòng; "thì tại ô cột E dòng e chèn" , có khả năng code ghi nhận sự thay đổi nên nó auto chèn thời gian cho tất cả các ô trong cùng hàng luôn ạ. e muốn kết quả trả về hàng đó là rỗng có cách nào không ạ.
 
Web KT
Back
Top Bottom