Email after column A has a change

HelpfulMe

New Member
Joined
Jul 26, 2013
Messages
1
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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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