longkurabe
Thành viên mới

- Tham gia
- 13/3/20
- Bài viết
- 16
- Được thích
- 0
Mã:
Sub TIM_SP_TRUNG_NHAU()
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
Set myrng = ws.Range("A8:A" & Range("A" & 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
If Application.WorksheetFunction.CountIf(myrng, cell) > 1 Then
If myrng.Find(what:=cell, lookat:=xlWhole, MatchCase:=False, after:=lastcell).Address = cell.Address Then
cell.Interior.ColorIndex = clr
clr = clr + 1
i = i + 1
Else
cell.Interior.ColorIndex = myrng.Find(what:=cell, lookat:=xlWhole, MatchCase:=False, after:=lastcell).Interior.ColorIndex
End If
End If
Next
MsgBox "Tong so co " & i & " loai SP trung nhau"
End Sub
