I'm trying to make excel send automated emails when different cells get to different values, my first if statement works, which is when cell D6 goes over 400, now my next if statement doesn't work, which is when cell D7 goes over 400. I have to at least add 2 more if statements like this for cell D8 and D9. Here is the code:
Dim R As Range
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Set R = Intersect(Range("D6"), Target)
If R Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 400 Then
Call send_mail_outlook
End If
'second part to check for
If Target.Cells.Count > 1 Then Exit Sub
Set R = Intersect(Range("D7"), Target)
If R Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 400 Then
Call send_mail_outlook1
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 = "Hola!" & vbNewLine & vbNewLine & _
"xxx" & vbNewLine & _
"xx"
On Error Resume Next
With y
.To = "xxx@ss"
.cc = ""
.BCC = ""
.Subject = "xxx"
.Body = z
.Display
End With
On Error GoTo 0
Set y = Nothing
Set x = Nothing
End Sub
Sub send_mail_outlook1()
Dim x As Object
Dim y As Object
Dim z As String
Set x = CreateObject("Outlook.Application")
Set y = x.CreateItem(0)
z = "ss!" & vbNewLine & vbNewLine & _
"sss" & vbNewLine & _
"sss"
On Error Resume Next
With y
.To = "xx@ss"
.cc = ""
.BCC = ""
.Subject = "xxx"
.Body = z
.Display
End With
On Error GoTo 0
Set y = Nothing
Set x = Nothing
End Sub