Good morning,
I'm running this code to send me an email when a value in my linked database changes which is set to auto refresh every 5 minutes, however this code will run each time the data source is refreshed and no specifically when there is new data, it could be the same data but refreshed.
This is what i want to happen if possible;![]()
Private Sub Worksheet_Change(ByVal Target As Range) Dim KeyCells As Range ' The variable KeyCells contains the cells that will ' cause an alert when they are changed. Set KeyCells = Range("B2:C2") If Not Application.Intersect(KeyCells, Range(Target.Address)) _ Is Nothing Then ' Display a message when one of the designated cells has been ' changed. Sheets("Data").Select ' Select the range of cells on the active worksheet. With Sheets("Data").Range("B1:E2") ActiveSheet.Range("B1:E2").Select End With ' Show the envelope on the ActiveWorkbook. ActiveWorkbook.EnvelopeVisible = True ' Set the optional introduction field thats adds ' some header text to the email body. It also sets ' the To and Subject lines. Finally the message ' is sent. With ActiveSheet.MailEnvelope '.Introduction = "" .Item.To = "[email protected]" .Item.Subject = "[Auto Mailer] - New Card - " & Format(Date, "ddmmyy") .Item.Send End With MsgBox "Cell " & Target.Address & " has changed." End If End Sub
Example: At 10:00 my data source refreshes and I have an entry in B2 as Test 1 > Send Email
At 10:05 my data source refreshes and I have an entry in B2 as Test 1 > Don't send as already sent
At 10:10 my data source refreshes and I have an entry in B2 as Test 2 > Send Email
Thanks in advance
DJ
Bookmarks