Sending Email from excel dependant on a calcuted cell
Posted by Phil on June 01, 2001 8:27 AM
********************************************
ORIGINAL MESSAGE BELOW
********************************************
Hi,
Does any1 know how i can send a set message (eg stock levels are low) through email - if a cells value drops below a certain level.
e.g.
collumn A has the min stock level
collumn b has the current stock level
i want an email to be set to me if the current stock level (collumn B) goes below the minimum stock level (collumn C)....
Any help is greatly appriecated
Phil
********************************************
END MESSAGE
********************************************
********************************************
NEW MESSAGE
********************************************
Dax gave me this piece of VBA for sending an email alert if the value of B drops below the value of A...
Unfortunatly it doesn't work if the value in "B" is a calculation - e.g =C1+C2
any1 got any suggestion.....
********************************************
END NEW MESSAGE
********************************************
below is the script from DAX (thanxs)...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim OLook As Object 'Outlook.Application
Dim Mitem As Object 'Outlook.Mailitem
Dim SendAnEmail As Boolean
'Is the changed cell in column A or B and not in row 1. If not then exit.
If (Target.Column <> 1) And (Target.Column <> 2) And (Target.Row <> 1) Then Exit Sub
If Target.Column = 1 Then 'Column A has changed
'Is column B value < column A value? Send an email if yes.
If Target.Offset(0, 1).Value < Target.Value Then SendAnEmail = True
Else
If Target.Column = 2 Then 'Column B has changed
'Is column A value > column B value? Send an email if yes.
If Target.Offset(0, -1).Value > Target.Value Then SendAnEmail = True
End If
End If
'If the SendAnEmail variable is true then this code sends an email
'from Outlook. Change the properties to suit your needs.
If SendAnEmail Then
Set OLook = CreateObject("Outlook.Application")
Set Mitem = OLook.createitem(0)
Mitem.to = "howell_p@manro-pc.com"
Mitem.Subject = "Stock level warning!"
Mitem.body = "Current stock level in " & Target.Row & " of spreadsheet" & _
" has fallen below minimum stock level"
Mitem.send
End If
'Destroy any object references
Set OLook = Nothing
Set Mitem = Nothing
End Sub