VBA code to send email when two cells in adjacent columns are contain specific data

rimilam

New Member
Joined
Aug 7, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have a code built that, upon clicking a command button, displays an email to a coworker when a cell in column P is "X". When a cell in column P is updated a date stamp is automatically entered into the adjacent cell in column Q. How do I update my code so the email displays only if the adjacent cell in Q is stamped with today's date? I'm trying to only send email notifications for the newly added Xs. I hope that makes sense. Here's a copy of my current code and a screenshot of my worksheet. TIA!!

Sub Button11_Click()
Dim OutMail As Object
Dim cell As Range

Application.ScreenUpdating = False

For Each cell In Range("P:P")
If cell.Value = "X" Then

On Error Resume Next
Set OutMail = CreateObject("Outlook.Application").CreateItem(0)
With OutMail
.To = "Harrison.holden@osteocentric.com"
.Subject = "New Tooling Requested"
.Body = "Hi there, " & vbNewLine & vbNewLine & _
"You have been assigned a new action item."
.Display
End With
On Error GoTo 0

End If
Next cell

Set OutMail = Nothing
Application.ScreenUpdating = True

End Sub

1607980719067.png
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
Would recommend inserting a column to keep track whether an email has been send.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,651
Messages
5,626,090
Members
416,161
Latest member
David1966Lewis

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
Top