Macro to send email to each line in a pivot table as well as using a sperate column to populate the subject.

tramirez

New Member
Joined
Dec 9, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am trying to send a separate email to each individual in a pivot table but also use a different column to populate the subject line. So essentially have email and topic in a pivot table. The email should be sent to each email address and use the topic for that email address to populate the subject line. This is working with the exception that it is creating everything twice likely due to my range. How can I get this to only send once?

VBA Code:
Sub Email()
Dim i As Integer, n As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
lra = Cells(Rows.Count, "B").End(xlUp).Row
Set Mail_Object = CreateObject("Outlook.Application")
For i = 7 To lr
For n = 7 To lra
        With Mail_Object.CreateItem(o)
            .Subject = Range("B" & n).Value
            .To = Range("A" & i).Value
            .Body = Range("B2").Value
            '.Send
            .display 'disable display and enable send to send automatically
    End With
Next n
Next i
        MsgBox "E-mail successfully sent", 64
        Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top