I'm trying to code for an email to be sent when there's an overdue action item. So far everything works except for the .To line. Right now, there are 2 possible recipients. Is there a way to run an IF statement to determine the email's recipient based on the value of another cell? Here's what I have now:
VBA Code:
Sub SendIssueEmails()
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Dim m As Workbook
Dim mI As Worksheet
Dim mILR As Long
Dim c As Range
Dim Recip As String
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Set m = ThisWorkbook
Set mI = m.Sheets("Inventory")
mILR = mI.Range("C" & Rows.Count).End(xlUp).Row
For Each c In mI.Range("AC3:AC" & mILR)
If c.Value > 0 Then
If c.Offset(0, -11).Value = "RB" Then
Set Recip = "RB@Company.com" 'I'm getting an Object Required error here.
ElseIf c.Offset(0, -11).Value = "MM" Then
Set Recip = "MM@Company.com"
End If
With OutlookMail
.To = Recip
.CC = "RB@Company.com"
.Subject = c.Offset(0, -26)
.Body = "The subject initiative has at least 1 overdue action item. Please review the action item and respond with justification for its delinquency."
.Display
End With
End If
Next c
End Sub