adding different conditions to email in VBA

rjmdc

Active Member
Joined
Apr 29, 2020
Messages
375
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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Watch MrExcel Video

Forum statistics

Threads
1,122,589
Messages
5,597,053
Members
414,118
Latest member
moversnpackers

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
Top