VBA to generate an email / vlookup ?

Dazzybeeguy

Board Regular
Joined
Jan 6, 2022
Messages
118
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I want to modify this VBA so that it looks at the cell being modified i.e E35 and instead of mentioning E35 in the generated email I want it to reference the date which would always be in cell 3 of that Row i.e E3

So if I change E35 it says Shift Change E35 In the 23/24 Roster '' One of your shifts was changed on 01/26/2023 at 07:50:09 by By Username.

I would like it to say A Shift Change has been made for the 4th June in the 23/24 Roster '' on the 01/26/2023 at 07:50:09 by By Username.

Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
'Generate Email on Shift Change
Dim xRgSel As Range
Dim xOutApp As Object
Dim xMailItem As Object
Dim xMailBody As String
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xRg = Range("d3:nd45")
Set xRgSel = Intersect(Target, xRg)
ActiveWorkbook.Save
If Not xRgSel Is Nothing Then
Set xOutApp = CreateObject("Outlook.Application")
Set xMailItem = xOutApp.CreateItem(0)
xMailBody = "Shift Change " & xRgSel.Address(False, False) & _
" In the 23/24 Roster '" & "' One of your shifts was changed on " & _
Format$(Now, "mm/dd/yyyy") & " at " & Format$(Now, "hh:mm:ss") & _
" by " & Environ$("username") & "Please check the Roster for fuller details "

With xMailItem
.To = "Email Address"
.Subject = "Shift Change Notification "
.Body = xMailBody
.Display
End With
Set xRgSel = Nothing
Set xOutApp = Nothing
Set xMailItem = Nothing
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Also what is the best way to turn this feature off. Sometimes there could be lots of changes that dont need an email.

Could the code include something that says only do this if the change is within 7 days
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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