adding different conditions to email in VBA

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
672
Office Version
  1. 365
Platform
  1. Windows
i have a macro to send an email if is date, i need to correct or add conditions but dont know how. i tried and just ruined the entire book
i need that if column 6 a- is date or b-"WITHDRAWN" or c-"ON HOLD" that the message is activated
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count = 1 Then
    If Target.Column = 6 And Target.Value <> "" Then
    If IsDate(ActiveCell) Then
        
            result = MsgBox("pressing OK will send email to notify", vbOK + vbExclamation, "Termination")
            If result = vbOK Then
                Set OutlookApp = CreateObject("Outlook.Application")
                Set OlObjects = OutlookApp.GetNamespace("MAPI")
                Set newmsg = OutlookApp.CreateItem(olMailItem)
                
                With newmsg
                    .Recipients.Add ("me@me.org") ' Add Recipients
                    .Subject = Cells(Target.Row, "A").Value & " has been terminated."    ' Add Subject
                    .Body = Cells(Target.Row, "A").Value & "   has been terminated on" & " " & Cells(Target.Row, "F").Value  ' Email Body
                    .Display 'Display Email
                    .Send 'Send Email
                End With

                MsgBox "Outlook message sent", , "Outlook message sent" ' Confirm Sent Email
            End If
          End If
    End If
  End If
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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