jeudi 3 décembre 2020

If duplicate then store cell.value from another cell. And use this variable in a string

I'm using an auto e-mail macro to e-mail some clients of us. Now i'm running against a problem that I don't know how to solve. The problem is as following: I have a list in column "A" with company names. Those company's have employees those employees are in column "B". Also in column "C" the date they started working there is shown. So it looks like this: Click here for example

And so on, so some have 10 employees some have 1 employee. I would like to send an e-mail to them with a standard text but in that text there should be the names of the employees and the start dates. Here is my code:

Sub mailen()

Dim namen As String
Dim r As Range
Dim inhoud As String
Dim names As string
Dim cdates As string

inhoud = "Hello client," & "<br>" & _
"Here some text that explains why we send this e-mail." & "<br>" & _
"It is about your employee(s): " & i & " " & "<br>" & _
"These employee(s) are working for you from the dates: " & c & "." & "<br>"


For Each r In Range("O2", Range("O2").End(xlDown))
    If r.Value = r.Offset(-1, 0).Value Then
        r.Value = r.Value
    Else: namen = r.Value
    
        With CreateObject("Outlook.Application").createitem(0)
        .To = namen
        .Subject = "Test"
        .HTMLbody = inhoud
        .attachments.Add ("C:\.pdf")
        .send
        End With
    End If
Next r
End Sub

In column "O" are the e-mail adresses where to send the e-mail to. Here my code skips the double values and works perfectly. But now i need to figure something out how to fill i with the names and c with the dates.

Can someone please help me with this one. Thanks already for every efford to help me.

Aucun commentaire:

Enregistrer un commentaire