Hello.
I searched the forum for VBA code to auto-send emails in outlook, and came up with the following, which I adjusted a little.
But would appreciate adjustments to fit my requirements if anyone can help. Any adjustments I tried resulted in errors or incorrect results.
Changes I would like(underlined);
1. If a number in a cell in N column changes to greater than 20%, or less than -20% an email is automatically sent.
2. Only one email per cell/row in each day 21:00 to 21:00.
(cells are auto-updated every 5 or so minutes. I only want a maximum of one email on the first breach of the +/- 20% threshold in each cell each day).
3. The email subject, and Body include the words from Column D and E, and the figure from Column N, from the same row as the trigger cell(N).
(These cells contain a category name(D), title(E), and the % number(N). )
Thank you in advance.
I searched the forum for VBA code to auto-send emails in outlook, and came up with the following, which I adjusted a little.
But would appreciate adjustments to fit my requirements if anyone can help. Any adjustments I tried resulted in errors or incorrect results.
Changes I would like(underlined);
1. If a number in a cell in N column changes to greater than 20%, or less than -20% an email is automatically sent.
2. Only one email per cell/row in each day 21:00 to 21:00.
(cells are auto-updated every 5 or so minutes. I only want a maximum of one email on the first breach of the +/- 20% threshold in each cell each day).
3. The email subject, and Body include the words from Column D and E, and the figure from Column N, from the same row as the trigger cell(N).
(These cells contain a category name(D), title(E), and the % number(N). )
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
On Error Resume Next
For Each rng In Intersect(Target, Range("N1:N500")).Cells
If rng.Value > 20 Then
With CreateObject("Outlook.Application").CreateItem(0)
.To = "me@yahoo.com"
.Subject = "Threshold Exceeded."
.Body = "Message"
.Send
End With
End If
Next
On Error GoTo 0
End Sub
Thank you in advance.