send auto email in excel

khoover12

New Member
Joined
May 20, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I am looking to send a email when the value in column H is < column I, I have this code below but when I change the value in column H it does not send a email. Please help!


Dim R As Range
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set R = Intersect(Range("H:H"), Target)
If R Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value < ("I:I") Then
Call send_mail_outlook
End If
End Sub
Sub send_mail_outlook()
Dim x As Object
Dim y As Object
Dim z As String
Set x = CreateObject("Outlook.Application")
Set y = x.CreateItem(0)
z = "Hello!" & vbNewLine & vbNewLine & _
"Current quantities are lower than min. quantities" & vbNewLine & _
"Please check inventory"
On Error Resume Next
With y
.To = ""
.cc = ""
.BCC = ""
.Subject = "Check Spare Parts Inventory"
.Body = z
.Send
End With
On Error GoTo 0
Set y = Nothing
Set x = Nothing
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I think your issue is with this line here:
Rich (BB code):
If IsNumeric(Target.Value) And Target.Value < ("I:I") Then
What exactly are you trying to do there?
It does not make sense to check if a single valud is less than a whole column.

If you are simply trying to check if the new value in column H is less than the value in column I of that same row, try this instead:
VBA Code:
If IsNumeric(Target.Value) And (Target.Value < Target.Offset(0, 1).Value) Then
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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