HÀM NÀY PHÁT HIỆN CHỈ CÓ 1 MÃ BỊ TRÙNG CHỨ KHÔNG PHÁT HIỆN MÃ TRÙNG KHI COPY 4 TẬP TIN TRUNG CÙNG LÚC. CÁC BẠN SỬA LẠI DÙNG MÌNH NHA! LÀM SAO PHÁT HIỆN NẾU CÓ MÃ TRÙNG TRONG CỘT B.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim Rng(), I As Long, Tem As Variant, K As Long
If Not Intersect(Target, [B2:B1000]) Is Nothing Then
If Target.Rows.Count = 1 Then
Rng = Sheet1.Range(Sheet1.[B2], Sheet1.[B65000].End(xlUp)).Value
For I = 1 To UBound(Rng, 1)
If UCase(Cells(I, 2)) = UCase(Target) Then
Cells(I, 2).Resize(, 2).Interior.ColorIndex = 36
K = K + 1
End If
Next
End If
If K > 1 Then
Tem = MsgBox("Chu Y! Ma Da Co Roi." & vbNewLine & "<OK> Tiep Tuc - <Cancel> Nhap lai", vbOKCancel, "Giai Phap Excel.")
If Tem = vbCancel Then Target.ClearContents: Target.Select
Sheet1.Cells.Interior.ColorIndex = 0
End If
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim Rng(), I As Long, Tem As Variant, K As Long
If Not Intersect(Target, [B2:B1000]) Is Nothing Then
If Target.Rows.Count = 1 Then
Rng = Sheet1.Range(Sheet1.[B2], Sheet1.[B65000].End(xlUp)).Value
For I = 1 To UBound(Rng, 1)
If UCase(Cells(I, 2)) = UCase(Target) Then
Cells(I, 2).Resize(, 2).Interior.ColorIndex = 36
K = K + 1
End If
Next
End If
If K > 1 Then
Tem = MsgBox("Chu Y! Ma Da Co Roi." & vbNewLine & "<OK> Tiep Tuc - <Cancel> Nhap lai", vbOKCancel, "Giai Phap Excel.")
If Tem = vbCancel Then Target.ClearContents: Target.Select
Sheet1.Cells.Interior.ColorIndex = 0
End If
End If
Application.EnableEvents = True
End Sub