Cần giúp đỡ về hiển thị thời gian nhập và khi thay đổi dữ liệu (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Tôi tuân thủ nội quy khi đăng bài

hiepnhau55

Thành viên mới
Tham gia
12/4/24
Bài viết
2
Được thích
0
Em đang muốn khi nhập dữ liệu vào bảng thông qua userform thì ở cột F sẽ hiển thị thời gian nhập, sau đó mỗi khi có chỉnh sửa dữ liệu thì thời gian sẽ được ghi nhận lại vào cột G ở dòng tương ứng mà trong đó thời gian ở cột F không thay đổi. Em đã cố gắng mò mấy hôm nay rồi mà không tìm ra được cách, nay đăng bài này lên rất mong nhận được sự giúp đỡ của quý anh chị!
Em có đính kèm file ở dưới để anh chị tiện xem xét, em xin cảm ơn trước ạ!
 

File đính kèm

Bạn dùng code này cho sheet nhập thông tin của bạn thử:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range

'Them moi*****
If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
Application.EnableEvents = False

For Each cell In Intersect(Target, Me.Columns("B"))
If cell.Value <> "" And Me.Cells(cell.Row, "F").Value = "" Then
Me.Cells(cell.Row, "F").Value = Now
End If
Next cell

Application.EnableEvents = True
End If

'Thay doi*****
If Not Intersect(Target, Me.Columns("B:E")) Is Nothing Then
Application.EnableEvents = False

For Each cell In Intersect(Target, Me.Columns("B:E"))
If cell.Value <> "" Then
Me.Cells(cell.Row, "G").Value = Now
End If
If Me.Cells(cell.Row, "F").Value = Me.Cells(cell.Row, "G").Value Then
Me.Cells(cell.Row, "G").Value = ""
End If
Next cell
Application.EnableEvents = True
End If

End Sub
 
Bạn dùng code này cho sheet nhập thông tin của bạn thử:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range

'Them moi*****
If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
Application.EnableEvents = False

For Each cell In Intersect(Target, Me.Columns("B"))
If cell.Value <> "" And Me.Cells(cell.Row, "F").Value = "" Then
Me.Cells(cell.Row, "F").Value = Now
End If
Next cell

Application.EnableEvents = True
End If

'Thay doi*****
If Not Intersect(Target, Me.Columns("B:E")) Is Nothing Then
Application.EnableEvents = False

For Each cell In Intersect(Target, Me.Columns("B:E"))
If cell.Value <> "" Then
Me.Cells(cell.Row, "G").Value = Now
End If
If Me.Cells(cell.Row, "F").Value = Me.Cells(cell.Row, "G").Value Then
Me.Cells(cell.Row, "G").Value = ""
End If
Next cell
Application.EnableEvents = True
End If

End Sub
Dạ code chạy rất đúng ý anh ạ. Cảm ơn anh đã bỏ thời gian giúp đỡ em nhé!
 
Web KT

Bài viết mới nhất

Back
Top Bottom