Private Sub Worksheet_Change(ByVal Target As Range)
Dim Ws As Worksheet
Dim LrD As Long, i&
Set Ws = Sheets("XUAT")
LrD = Ws.Range("D65536").End(xlUp).Row
If Not Application.Intersect(Range("D4", "D" & LrD), Range(Target.Address)) Is Nothing Then
Ws.Range("E" & ActiveCell.Row & ":" & "F" & ActiveCell.Row).ClearContents
If Ws.Range("A" & ActiveCell.Row).Value = "" Then
Ws.Range("C" & ActiveCell.Row & ":" & "H" & ActiveCell.Row).ClearContents
MsgBox "De nghi nhap: Ngay, Thang, Nam...! "
End If
End If
If Application.Intersect(Target, Ws.Range("B4:B10000")) Is Nothing Then
i = Target.Row
If Application.WorksheetFunction.CountIf(Ws.Range("B" & i & ":F" & i), "***") = 1 Then
Application.EnableEvents = False
Ws.Range("B3:F3").Copy Ws.Range("B" & i)
Application.EnableEvents = True
End If
End If
End Sub
[/QUOTE]
[/QUOTE]
[automerge]1695876429[/automerge]
[QUOTE="HUONGHCKT, post: 1116207, member: 731215"]
Sáng ra, làm đại 1 quả, hy vọng đúng ý.
Thay code cũ bằng code này:
[CODE]
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Ws As Worksheet
Dim LrD As Long, i&
Set Ws = Sheets("XUAT")
LrD = Ws.Range("D65536").End(xlUp).Row
If Not Application.Intersect(Range("D4", "D" & LrD), Range(Target.Address)) Is Nothing Then
Ws.Range("E" & ActiveCell.Row & ":" & "F" & ActiveCell.Row).ClearContents
If Ws.Range("A" & ActiveCell.Row).Value = "" Then
Ws.Range("C" & ActiveCell.Row & ":" & "H" & ActiveCell.Row).ClearContents
MsgBox "De nghi nhap: Ngay, Thang, Nam...! "
End If
End If
If Application.Intersect(Target, Ws.Range("B4:B10000")) Is Nothing Then
i = Target.Row
If Application.WorksheetFunction.CountIf(Ws.Range("B" & i & ":F" & i), "***") = 1 Then
Application.EnableEvents = False
Ws.Range("B3:F3").Copy Ws.Range("B" & i)
Application.EnableEvents = True
End If
End If
End Sub