minh nham nhe, ban chay thu lai vs code duoi nay xem sao ( vao module nhe )
Sub Highlight_Duplicate()
Dim ws As Worksheet
Dim cell As Range
Dim myrng As Range
Dim clr As Long
Dim lastcell As Range
Dim i As Long
Dim lastrow As Long
Set ws = ThisWorkbook.ActiveSheet
'Vung can danh dau gia tri trung nhau
Set myrng = ws.Range("B8:B" & Range("B" & ws.Rows.Count).End(xlUp).Row)
With myrng
Set lastcell = .Cells(.Cells.Count)
End With
myrng.Interior.ColorIndex = xlNone
clr = 3
For Each cell In myrng
'Kiem tra so gia tri trung nhau trong vung, neu co hai gia tri trung nhau tro len thi thuc hien
If Application.WorksheetFunction.CountIf(myrng, cell) > 1 Then
'Neu la o dau tien cua cac gia tri trung nhau trong vung
If myrng.Find(what:=cell, lookat:=xlWhole, MatchCase:=False, after:=lastcell).Address = cell.Address Then
'Thiet lap mau
cell.Interior.ColorIndex = clr
clr = clr + 1
i = i + 1
Else
'Thiet lap mau tu o thu 2 voi cac gia tri trung nhau
cell.Interior.ColorIndex = myrng.Find(what:=cell, lookat:=xlWhole, MatchCase:=False, after:=lastcell).Interior.ColorIndex
End If
End If
Next
'Lay dong cuoi cung cua vung du lieu
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A" & lastrow + 2).Value = "Tong so co " & i & " gia tri trung nhau"
End Sub