我以前在A栏空白工作表数据,并输出放B列被 可以更改循环和单元格引用,以满足您的需求。 我还假定您希望单元格中包含的电子邮件地址在输出中保持分组(一旦删除重复项)。
此代码还通过一个“回车”
Sub removeDuplicate()
'references: http://stackoverflow.com/questions/3017852/vba-get-unique-values-from-array
Dim wks As Worksheet
Dim rng As Range
Dim wordCount As Integer
Dim d As Object
Dim i As Integer
Dim j As Integer
Dim v As Variant
Dim outText As String
Set wks = Worksheets("Sheet1") '<- change sheet to suit needs
For j = 1 To 2 '<- change loop to suit needs
Set rng = wks.Range(Cells(j, 1), Cells(j, 1)) '<- change cell reference as required
Set d = CreateObject("Scripting.Dictionary")
'use carriage return (chr(10)) as the 'find' text
'Count Words/email addresses
wordCount = Len(rng) - Len(Replace(rng, Chr(10), "")) + 1
'split words by carriage return
arrWords = Split(rng, Chr(10))
For i = 0 To wordCount - 1
d(arrWords(i)) = 1
Next i
'create output text by re-grouping the split text.
outText = ""
For Each v In d.keys
If outText = "" Then
outText = v
Else
outText = outText & Chr(10) + v
End If
Next v
'output to adjacent cell
rng.Offset(0, 1).Value = outText
Set d = Nothing
Next j
Set wks = Nothing
End Sub
假定地址被分隔的电子邮件