Home Articles

删除excel单元格列中的重复单词

Asked
Viewed 1723 times
-2

我需要摆脱一列电子表格单元格中重复的单词 .

我可以使用Excel或OpenOffice .

我想摆脱细胞中任何重复的单词...例如......快乐,悲伤,有趣,快乐,愚蠢,悲伤,笨蛋, - 会变得 - 快乐,悲伤,有趣,愚蠢,笨蛋,(删除重复的单词 . )

我需要一步一步指导如何创建宏并将其应用于违规单元格列!谢谢你的帮助!

2 Answers

  • 0

    选择要处理的单元格并运行以下简单宏:

    Sub CellKleaner()
        Dim c As Collection, r As Range, v As String
        Dim v2 As String
        For Each r In Selection
            v = r.Text
            If InStr(1, v, ",") > 0 Then
                Set c = New Collection
                ary = Split(v, ",")
                v2 = ary(0)
                c.Add ary(0), CStr(ary(0))
                For i = LBound(ary) To UBound(ary)
                    On Error Resume Next
                    c.Add ary(i), CStr(ary(i))
                    If Err.Number > 0 Then
                        Err.Number = 0
                        On Error Resume Next
                    Else
                        v2 = v2 & "," & ary(i)
                    End If
                Next i
                r.Value = v2
                Set c = Nothing
            End If
        Next r
    End Sub
    
  • 0

    数据透视表可用于删除单元格之间的重复项:

    enter image description here

Related