You are on page 1of 1

Private Sub Worksheet_Change(ByVal Target As Range)

Dim ws As Worksheet

Set ws = Worksheets("Sheet1") 'Replace "Sheet1" with the name of your worksheet

Dim minStock As Integer

minStock = 10 'Replace 10 with the minimum stock level you want to use

If Intersect(Target, ws.Range("B:B")) Is Nothing Then Exit Sub 'Replace "B:B" with the column letter
for your stock levels

If Target.Value < minStock Then

Dim OutApp As Object

Dim OutMail As Object

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)

With OutMail

.To = "recipient@example.com" 'Replace with the email address of the recipient

.Subject = "Low stock notification"

.Body = "The stock level for item " & Target.Offset(0, -1).Value & " has fallen below the
minimum level of " & minStock & "."

.Send

End With

Set OutMail = Nothing

Set OutApp = Nothing

End If

End Sub

You might also like