删除重复项,但荣誉案例

时间:2015-11-20 14:12:41

标签: excel excel-vba vba

我需要删除数据中的重复项:

enter image description here

我使用的代码如下:

Level

产生:

enter image description here

我想保留具有相同字母序列但不同情况的字词。我怎么能实现这个?

2 个答案:

答案 0 :(得分:3)

您可以使用以下代码。假设数据在A1到A7的范围内,对于不同的范围,您可以修改代码。

Dim oDic As Object, vData As Variant, r As Long

Set oDic = CreateObject("Scripting.Dictionary")

With Range("A1:A7")
    vData = .Value
    .ClearContents
End With

With oDic
    .comparemode = 0
    For r = 1 To UBound(vData, 1)
        If Not IsEmpty(vData(r, 1)) And Not .Exists(vData(r, 1)) Then
            .Add vData(r, 1), Nothing
        End If
    Next r
    Range("A1").Resize(.Count) = Application.Transpose(.keys)
End With

答案 1 :(得分:2)

这是一种可能适合您的方法。 (它显然有一些粗略的编码元素,但我认为你得到了图片,可以根据需要修复任何东西):

Sub RespectCase()

Dim rSearch As Range, cel As Range, rFound As Range
Set rSearch = Range("G1:G10")
Set rFound = Range("J1:J10")

For Each cel In rSearch

    Dim rMatch As Range
    Set rMatch = rFound.Find(cel, LookAt:=xlWhole, MatchCase:=True)

    If rMatch Is Nothing Then

        Range("J10").End(xlUp).Offset(1).Value = cel

    End If

Next

End Sub