Sub test()
Dim arr, brr()
Dim I As Integer, j As Integer
Dim Dict As Object
On Error Resume Next
Set Dict = CreateObject("scripting.dictionary")
With ActiveSheet
arr = Intersect(.UsedRange, .Columns(1))
For I = 1 To UBound(arr)
If Dict.exists(arr(I, 1)) Then
Dict.Item(arr(I, 1)) = Dict.Item(arr(I, 1)) + 1
Else
Dict.Item(arr(I, 1)) = 1
End If
Next I
For I = 1 To UBound(arr)
j = j + 1
ReDim Preserve brr(1 To j)
brr(j) = IIf(Dict.Item(arr(I, 1)) = 1, "唯一", "重复")
Next I
.Columns(2).ClearContents
.Range("b1").Resize(UBound(brr), 1) = WorksheetFunction.Transpose(brr)
End With
End Sub
追问语句好长,数据量8万左右,运行会不会慢?
追答Sub test()
Application.ScreenUpdating = False
Dim arr, brr()
Dim i As Long, j As Long
Dim Dict As Object
On Error Resume Next
Set Dict = CreateObject("scripting.dictionary")
With ActiveSheet
arr = Intersect(.UsedRange, .Columns(1))
ReDim brr(1 To UBound(arr), 1 To 1)
For i = 1 To UBound(arr)
If Dict.exists(arr(i, 1)) Then
Dict.Item(arr(i, 1)) = Dict.Item(arr(i, 1)) + 1
Else
Dict.Item(arr(i, 1)) = 1
End If
Next i
For i = 1 To UBound(arr)
j = j + 1
brr(j, 1) = IIf(Dict.Item(arr(i, 1)) = 1, "唯一", "重复")
Next i
.Columns(2).ClearContents
.Range("b1").Resize(UBound(brr), 1) = brr
End With
Application.ScreenUpdating = True
End Sub
我电脑运行了1.3秒
追问给跪了!如果从第二行开始,表头不包括,怎么改?另外,如果判断由A、B换到C、D,怎么改?
本回答被提问者采纳