Hi all! I'm having trouble figuring out what is wrong with my excel macro, I am trying to run this macro that when a value in column A (it can only be 3 values S, C, or D) changes it sends an email to the appropriate person. For example if it is changed to S it sends an email to S@email.com and if it's changed to D it sends an email to D@email.com (etc.) I'm still new to excel so I'm not sure if I'm even on the right track with this "code" but it's what I've compiled from searching this site. Can anyone help me?
Sub SendMail()
Dim OutApp As Object
Dim OutMail As Object
Dim Status As Range
Dim lastRow As Long
Dim EquipmentCell As Long
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For Each Status In Range("A2:A" & lastRow)
If Status = " " Then GoTo 1
' This is for the Supplies
If Status = "S" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
' Change the reciever here
.To = "S@email.com"
' Change your massage subject here
.Subject = "Status Changed"
'Change body of the massage here
.Body = "The status of " & Cells(Status.Row, "F").Value & _
" is changed to " & Cells(Status.Row, "F").Value _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Helpful Me"
.send
End With
Set OutMail = Nothing
End If
Cells(Status.Row, "A").Value = datecell
' This is for the counter
If Status = "C" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "C@email.com"
.Subject = "Status Changed" ' Change your massage subject here
'Change body of the massage here
.Body = "The status of " & Cells(Status.Row, "F").Value & _
" is changed to " & Cells(Status.Row, "F").Value _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Helpful Me"
.send
End With
Set OutMail = Nothing
End If
Cells(Status.Row, "A").Value = datecell
' This is for Delivery
If Status = "D" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "D@email.com"
.Subject = "Status Changed" ' Change your massage subject here
'Change body of the massage here
.Body = "The status of " & Cells(Status.Row, "F").Value & _
" is changed to " & Cells(Status.Row, "F").Value _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Helpful Me"
.send
End With
Set OutMail = Nothing
End If
Cells(Status.Row, "A").Value = datecell
1: Next Status
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
Sub SendMail()
Dim OutApp As Object
Dim OutMail As Object
Dim Status As Range
Dim lastRow As Long
Dim EquipmentCell As Long
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For Each Status In Range("A2:A" & lastRow)
If Status = " " Then GoTo 1
' This is for the Supplies
If Status = "S" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
' Change the reciever here
.To = "S@email.com"
' Change your massage subject here
.Subject = "Status Changed"
'Change body of the massage here
.Body = "The status of " & Cells(Status.Row, "F").Value & _
" is changed to " & Cells(Status.Row, "F").Value _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Helpful Me"
.send
End With
Set OutMail = Nothing
End If
Cells(Status.Row, "A").Value = datecell
' This is for the counter
If Status = "C" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "C@email.com"
.Subject = "Status Changed" ' Change your massage subject here
'Change body of the massage here
.Body = "The status of " & Cells(Status.Row, "F").Value & _
" is changed to " & Cells(Status.Row, "F").Value _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Helpful Me"
.send
End With
Set OutMail = Nothing
End If
Cells(Status.Row, "A").Value = datecell
' This is for Delivery
If Status = "D" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "D@email.com"
.Subject = "Status Changed" ' Change your massage subject here
'Change body of the massage here
.Body = "The status of " & Cells(Status.Row, "F").Value & _
" is changed to " & Cells(Status.Row, "F").Value _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Helpful Me"
.send
End With
Set OutMail = Nothing
End If
Cells(Status.Row, "A").Value = datecell
1: Next Status
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub