Need to edge out the competition for your dream job? Train for certifications today.
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
Dim rng1 As Range, rng2 As Range, rng3 As Range
Dim cel As Range
Dim MyDic As Object
Dim doit, FirstAddress As String
Set MyDic = CreateObject("Scripting.Dictionary")
Set rng1 = Sheets(1).Range([f2], Cells(ActiveSheet.Rows.Count, "f").End(xlUp)).SpecialCells(xlConstants)
For Each cel In rng1
Set rng3 = Nothing
If cel.Value <> vbNullString Then
If Not MyDic.exists(cel.Value) Then
Set rng2 = rng1.Find(cel.Value, rng1.Cells(1), xlValues, xlWhole, xlByRows, xlPrevious)
If Not rng2 Is Nothing Then
Set rng3 = Range(Cells(rng2.Row, "A"), Cells(rng2.Row, "E"))
FirstAddress = rng2.Address
Set rng2 = rng1.FindNext(rng2)
Set rng3 = Union(rng3, Range(Cells(rng2.Row, "A"), Cells(rng2.Row, "E")))
Loop While FirstAddress <> rng2.Address
MyDic.Add cel.Value, cel.Row
Set doit = Mailem(cel.Value, rng3)
Function Mailem(Recip As String, ByVal rng3 As Range)
Dim outApp, outMail
Dim tempStrStart As String, tempStrMid As String, tempStrFinish As String, tempStrCel As String, tempStr As String
Dim r As Range, cel As Range
Set outApp = CreateObject("Outlook.Application")
tempStrStart = "<table border=1><tr><th>Groups</th><th>Full Name</th><th>Title</th><th>Description</th><th>Department</th></tr>"
tempStrFinish = "</table>"
For Each r In rng3.Rows
tempStrCel = vbNullString
For Each cel In r.Cells
tempStrCel = tempStrCel & "<td>" & cel.Value & "</td>"
tempStrMid = tempStrMid & tempStrCel & "</tr>"
tempStr = tempStrStart & tempStrMid & tempStrFinish
Set outMail = outApp.CreateItem(0)
.To = Recip
.Subject = "Groups"
.htmlBody = "Hi " & Recip & ",<br>Below is the data.<br><br>" & tempStr & "<br><br>Regards<br>Sharath"
Set outMail = Nothing
Set outApp = Nothing
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment