|
try this:
- Sub dd()
- Dim d As Object, arr, brr, i&, j&, k, r%
- Dim rng As Range, rng1 As Range
- Dim rg As Object, s$
- Set rg = CreateObject("vbscript.regexp")
- Set rng = Selection
- Set d = CreateObject("scripting.dictionary")
- On Error GoTo ex
- If Selection.Count = Application.CountBlank(rng) Then
- Set rng = Application.InputBox("请选择需要处理的数据", "数据范围", Type:=8)
- GoTo last
- Else
- GoTo last
- End If
- last:
- arr = Range(rng.Address)
- r = rng(1).Row - 1
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = d(arr(i, 1)) & "," & i + r
- Next
- For i = 1 To UBound(arr)
- t = Mid(d(arr(i, 1)), 2)
- If InStr(t, ",") Then
- rg.Pattern = "\b(" & i + r & ",)|(," & i + r & "\b)"
- arr(i, 1) = "与第" & rg.Replace(t, "") & "行重复"
- s = s & "|" & i + r
- Else: arr(i, 1) = ""
- End If
- Next
- rng(1)(1, 2).Resize(UBound(arr), 1).Interior.Color = xlNone
- rng(1)(1, 2).Resize(UBound(arr), 1) = arr
- j = rng(1)(1, 2).Column
- brr = Split(s, "|")
- For i = 1 To UBound(brr)
- Cells(brr(i), j).Interior.Color = 60000
- Next
- Set d = Nothing: Set rg = Nothing
- MsgBox "数据验证完成!", vbInformation, "提示"
- Exit Sub
- ex:
- MsgBox "操作已取消,程序退出!", vbInformation, "提示"
- End Sub
复制代码
HTH
|
|