|
Sub 颜色标识重复值()
Dim ws As Worksheet
Dim rng As Range
Dim lastRow As Long, lastCol As Long
Dim dict As Object
Dim cell As Range
Dim key As String
Dim i As Long, j As Long
Set ws = ActiveSheet
lastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set rng = ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, 1))
rng.FormatConditions.Delete
Set dict = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
dict.RemoveAll
If Application.CountA(ws.Columns(1)) > 0 Then
For i = 1 To lastRow
If Not IsEmpty(ws.Cells(i, 1)) Then
key = CStr(ws.Cells(i, 1).Value)
If dict.Exists(key) Then
dict(key) = dict(key) + 1
Else
dict.Add key, 1
End If
End If
Next i
For i = 1 To lastRow
If Not IsEmpty(ws.Cells(i, 1)) Then
key = CStr(ws.Cells(i, 1).Value)
If dict(key) > 1 Then
ws.Cells(i, 1).Interior.Color = RGB(255, 199, 206)
ws.Cells(i, 1).Font.Color = RGB(156, 0, 6)
End If
End If
Next i
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
MsgBox "处理完成!共处理 " & lastRow & " 行数据。"
End Sub
|
|