我需要帮助为Excel创建一个计算一列名称的宏。如果名称出现2次或更多次,请删除重复项。如果出现的次数少于2次,请从列表中删除该名称。有人可以帮忙吗?
例如,列:
宏变成:
答案 0 :(得分:0)
你可以试试这个..
假设它是单元格A1 ..您将在B列中获得结果..您可以在获得结果后删除C列。
Sub CheckOccurance()
Dim LastA, r As Range
Dim x, x2, Bn As Long
Dim s As String
Dim IsDoub As Boolean
Set LastA = Range("A65536").End(xlUp)
Bn = 1
For x = 1 To LastA.Row
If Not Cells(x, 3) = "x" Then
s = Cells(x, 1)
Cells(x, 3) = "v"
IsDoub = False
For x2 = x + 1 To LastA.Row
If Cells(x2, 1) = s Then
Cells(x2, 3) = "x"
IsDoub = True
End If
Next
If IsDoub Then
Cells(Bn, 2) = s
Bn = Bn + 1
End If
End If
Next
End Sub