VBA for auto sending email notifications.

DPFIN

New Member
Joined
Jun 5, 2018
Messages
1
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). )



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.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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