下面的代碼在新工作表上創建了一組新的數據,但它將所有與需求匹配的內容即使是重複的。如何更改代碼以消除新數據集中的重複項?vba刪除新集中的重複項
Sub Testerss()
Dim c As Range, v As String, arr, x As Long, e
Dim d As Range
Dim ws As Worksheet
Set d = Worksheets("Sheet3").Range("D1")
For Each c In ActiveSheet.Range("D25:D105")
v = Trim(c.Value)
If Len(v) > 0 Then
v = Replace(v, vbLf, " ")
Do While InStr(v, " ") > 0
v = Replace(v, " ", " ")
Loop
arr = Split(v, " ")
For x = LBound(arr) To UBound(arr)
e = arr(x)
If Not IsError(Application.Match(LCase(e), Array("(bye)", "(hello)"), 0)) Then
If x > LBound(arr) Then
d.Value = arr(x - 1) & " " & e
Else
d.Value = "??? " & e
End If
Set d = d.Offset(1, 0)
End If
Next x
End If
Next c
End Sub
[Range.RemoveDuplicates()](https://msdn.microsoft.com/en-us/library/office/ff193823.aspx)可能有用。 – jsheeran