VBA to send 2 different emails from 2 different columns if they change

amwu

New Member
Joined
Jul 30, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have a working VBA Macro that sends an email if the value in column I changes. How do I change this so that it sends a different email to someone else if the value in Column M changes?
This is a snippet of my current code. Do I create another "Private Sub"? or just repeat what I need before the "End Sub" and redefine the range to "M:M"?

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("I:I"), Target)
If xRg Is Nothing Then Exit Sub
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim R As Long
......
With xOutMail
.To = "email address"
.CC = ""
.BCC = ""
.Subject = "For Your Review"
' .Body = FileType & ": " & Filename & " has been submitted for your Review by " & Originator
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
 

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.
Hi amwu,

maybe try the change of codeline
Code:
Set xRg = Intersect(Range("I:I"), Target)
to
Code:
Set xRg = Intersect(Range("I:I,M:M"), Target)
Ciao,
Holger
 
Upvote 0
Thanks - I see, but how can I change the contents of xOutMail? Message and recipient will be totally different. Maybe query the current column and then set up the email contents?
 
Upvote 0
Hi amwu,

you could try something like
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRg As Range
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim R As Long
'On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("I:I, M:M"), Target)
If xRg Is Nothing Then Exit Sub
Select Case xRg.Column
  Case 9
    'data for first mail
  Case 13
    'data for second mail
End Select
....
Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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