Hi,
I'm using the below syntax in VBA to send multiple emails with attachments and it's working fine - however I would like the VBA to only send email to those recipients if in Column Y says Yes, if it says No then don't send email. Please could someone guide me. Thank you
I'm using the below syntax in VBA to send multiple emails with attachments and it's working fine - however I would like the VBA to only send email to those recipients if in Column Y says Yes, if it says No then don't send email. Please could someone guide me. Thank you
Code:
Option Explicit
Sub send_multiple_emails()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
Dim OA As Object
Dim msg As Object
Set OA = CreateObject("Outlook.application")
Dim i As Integer
Dim last_row As Integer
last_row = Application.WorksheetFunction.CountA(sh.Range("H:H"))
For i = 2 To last_row
Set msg = OA.createitem(0)
msg.to = sh.Range("H" & i).Value
msg.cc = sh.Range("I" & i).Value
msg.Subject = "Sales Report"
msg.body = sh.Range("M" & i).Value
If sh.Range("J" & i).Value <> "" Then
msg.attachments.Add sh.Range("J" & i).Value
End If
msg.display
Next i
End Sub