Hello rain4u,
The macro below setups up both the recipients and CC email columns "H3" and "I3" with the unique addresses separated by a semi-colon and a space. It has been added to the attached workbook.
' Thread: http://www.excelforum.com/excel-programming/793315-concatenating-unique-cells-vertically-leaving-between-results-for-emails.html
' Poster: rain4u
' Written: September 21, 2011
' Author: Leith Ross
Sub CreateEmailLists()
Dim Dict As Object
Dim ListCell As Range
Dim R As Long
Dim Recipients As String
Dim Rng As Range
Dim RngEnd As Range
Dim StartRng As Range
Dim Wks As Worksheet
Set Wks = Worksheets("Before")
Set ListCell = Wks.Range("H3")
Set StartRng = Wks.Range("H8")
GoSub CreateList
Set ListCell = Wks.Range("I3")
Set StartRng = Wks.Range("I8")
GoSub CreateList
Exit Sub
CreateList:
Set RngEnd = Wks.Cells(Rows.Count, StartRng.Column).End(xlUp)
If RngEnd.Row < StartRng.Row Then Exit Sub Else Set Rng = Wks.Range(StartRng, RngEnd)
Set Dict = CreateObject("Scripting.Dictionary")
Dict.CompareMode = vbTextCompare
For R = 1 To Rng.Rows.Count
If StartRng.Item(R, 1) <> "" Then
If Not Dict.Exists(Rng.Item(R, 1).Value) Then
Dict.Add Rng.Item(R, 1).Value, R
Recipients = Recipients & Rng.Item(R, 1) & "; "
End If
End If
Next R
ListCell = Left(Recipients, Len(Recipients) - 2)
Return
End Sub
Bookmarks