This works great but only if the cells are changed directly erasing the formula. Each of the cells in my range contains a VLOOKUP formula that fetches a value from a long list of data in a separate sheet. These values are imported from a database and are refreshed every so often. Basically I need an alternative that triggers the email when cells change through the formula. I hope that makes sense.
Dim xRg As Range
'Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Target, Range("N1:N999"))
If xRg Is Nothing Then Exit Sub
If (Range("N45") = Range("F45")) Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
xRg.Offset(0, -12) & " has reached its target"
On Error Resume Next
With xOutMail
.To = "***@****.com"
.CC = ""
.BCC = ""
.Subject = "Target Reached"
.Body = xMailBody
.Send 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub