Including a cell value in the body of an email

ryeire

New Member
Joined
Jan 31, 2022
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a code here for logging data and sending emails automatically.

I want to be able to send an email when column E has 'Yes' in it and I want the body of an email to include the corresponding cell in column G.

I have code to send the email I just can't find a way to get the corresponding cell value in column G to be part of the body. I have been able to include an exact cell (e.g. cell G2) but this is not what I need. I have also tried to use ActiveCell but this wont work as the user fills in the data with a userform. I will include the code below.

I hope this makes sense and someone is able to help me with it. Thanks in advance.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 5 Then Exit Sub
    Application.ScreenUpdating = False
    Dim OutApp As Object, OutMail As Object
    If Target = "Yes" Then
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        X = Range("G" & ActiveCell.Row).Value
        With OutMail
            .To = ""
            '.CC = ""
            .Subject = "ESD Station Needs Repair"
            .HTMLBody = "Hi,<br>" & "<br>" & "The following stations need repair:  " & X
            .Display    'change to .send
        End With
    End If
    Application.ScreenUpdating = True
End Sub
 
Excellent! You are welcome.
Glad to hear that we were finally able to identifty and fix the issue.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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