Automatically Send Emails from Excel Based on Cell Content (2 Methods)

The sample dataset below contains the information of several sales representatives of Armani Group. The name of the sales representatives, their Identification Number, types of Products and the Revenue Earned by the sales representatives are given in Columns B, C, D and E.

Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content


Method 1 – Run a VBA Code to Send Email Automatically from Excel Based on Cell Content

Step 1:

  • Open a Module. From your Developer tab, go to,

Developer → Visual Basic

Run a VBA Code to Send Email Automatically from Excel Based on Cell Content

  • Click on the Visual Basic ribbon, a window named Microsoft Visual Basic for Applications will open. Insert a module for applying our VBA code. Go to,

Insert → Module

Step 2:

  • The Send Mail from Excel module will appear. Enter theVBA code below,
Dim R As Range
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set R = Intersect(Range("D6"), Target)
If R Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 400 Then
Call send_mail_outlook
End If
End Sub
Sub send_mail_outlook()
Dim x As Object
Dim y As Object
Dim z As String
Set x = CreateObject("Outlook.Application")
Set y = x.CreateItem(0)
z = "Hello!" & vbNewLine & vbNewLine & _
"Hope you are well" & vbNewLine & _
"Visit our Exceldemy site"
On Error Resume Next
With y
.To = "Address"
.cc = ""
.BCC = ""
.Subject = "send mail based on cell value"
.Body = z
.Display
End With
On Error GoTo 0
Set y = Nothing
Set x = Nothing
End Sub

automatically send emails from excel based on cell content

  • Run the VBA. 

Run → Run Sub/UserForm

  • If the cell value in cell D6 > 400, an email in Outlook will generate automatically with specific recipients. Click on the Send button to send the email as shown in the image below.

Run a VBA Code to Send Email Automatically from Excel Based on Cell Content

Read More: How to Send Automatic Email from Excel to Outlook


Method 2 – Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content

Step 1:

  • Open your Word file and enter your message.

  • From the Mailing tab, go to,

Mailings Select Recipients Use an Existing List

Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content

  • The Select Data Source dialog box will pop out. Select the Excel file where the Email addresses are stored. Click Open.

  • The Select Table dialog box will pop up. Choose the sheet and press OK.

Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content

Step 2:

  • Select the word you need to replace for each mail. In this example, we chose Carl. Under the Mailings tab, go to,

Mailings → Write & Insert Field → Insert Merge Field → Sales_Rep

  • It will return the message as shown in the image below.

Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content

  • Click Preview Results to see a preview of the mail from the recipient’s perspective.

  • From the Mailing tab, go to,

Mailing → Finish → Finish & Merge → Send Email Messages

Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content

  • The Merge to E-mail dialog box will pop up. Choose the header Sales_Rep in the To field and enter your Subject line (Greetings). Press OK to dispatch the mails.

Use Mail Merge Command in Word to Send Email Automatically from Excel Based on Cell Content

Read More: How to Send Excel File to Email Automatically


Things to Remember

You can open Microsoft Visual Basic for Applications window by pressing Alt + F11.

If a Developer tab is not visible in your ribbon, you need to add it. Go to

File → Option → Customize Ribbon


Download Practice Workbook


Related Articles

<< Go Back To Send Email from Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Abdur Rahim Rasel
Md. Abdur Rahim Rasel

MD. ABDUR RAHIM is a marine engineer proficient in Excel and passionate about programming with VBA. He views programming as an efficient means to save time while managing data, handling files, and engaging with the internet. His interests extend to Rhino3D, Maxsurf C++, AutoCAD, Deep Neural Networks, and Machine Learning, reflecting his versatile skill set. He earned a B.Sc in Naval Architecture & Marine Engineering from BUET, and now he has become a content developer, creating technical content... Read Full Bio

4 Comments
  1. How can I set the code if I want it to send an email if D1>7 but also send an email if D5>2?

    I don’t need both to be met to send the email but want to send whenever either of them are met.

    • Reply Avatar photo
      Md. Abdur Rahim Rasel Jul 27, 2023 at 3:18 PM

      Hi MEAGAN!
      You can set the below VBA code to send an email if D1>7 but also send an email if D5>2. The VBA code is:

      Dim R As Range
      Private Sub Worksheet_Change(ByVal Target As Range)
      	On Error Resume Next
      	If Target.Cells.Count > 1 Then Exit Sub
      	Set R = Intersect(Range("D1,D5"), Target) ' Combine D1 and D5 ranges
      	If R Is Nothing Then Exit Sub
      	If IsNumeric(Target.Value) Then
          	If (Target.Address = "$D$1" And Target.Value > 7) Or (Target.Address = "$D$5" And Target.Value > 2) Then
              	Call send_mail_outlook
          	End If
      	End If
      End Sub
      
      Sub send_mail_outlook()
      	Dim x As Object
      	Dim y As Object
      	Dim z As String
      	Set x = CreateObject("Outlook.Application")
      	Set y = x.CreateItem(0)
      	z = "Hello!" & vbNewLine & vbNewLine & _
          	"Hope you are well" & vbNewLine & _
          	"Visit our Exceldemy site"
      	On Error Resume Next
      	With y
          	.To = "Address"
          	.cc = ""
          	.BCC = ""
          	.Subject = "send mail based on cell value"
          	.Body = z
          	.Display
      	End With
      	On Error GoTo 0
      	Set y = Nothing
      	Set x = Nothing
      End Sub

      Please download the Excel file for solving your problem and practice with it.
      Automatically Send Emails from Excel Based on Cell Content.xlsm
      If you cannot solve your problem, please mail us at the address below.
      [email protected]
      Thank you for being with us.
      Regards
      Md. Abdur Rahim Rasel
      Exceldemy Team

  2. Hi,
    This works great for numerical values, but how would you compose it for text values.

    I tried changing “IsNumeric” to “IsText” but failed.

    Thanks,
    Paul

    • Reply Avatar photo
      Md. Abdur Rahim Rasel Aug 13, 2023 at 12:45 PM

      Hello PAUL!
      Thanks for your feedback.
      You can use the following VBA code to change “IsNumeric” to “IsText” for composing the text values instead of numeric values.

      Dim R As Range
      Private Sub Worksheet_Change(ByVal Target As Range)
      	On Error Resume Next
      	If Target.Cells.Count > 1 Then Exit Sub
      	Set R = Intersect(Range("D6"), Target)
      	If R Is Nothing Then Exit Sub
          
      	' Check if the new value in the changed cell is a text string
      	If IsText(Target.Value) Then
          	Call send_mail_outlook
      	End If
      End Sub
      
      Sub send_mail_outlook()
      	Dim x As Object
      	Dim y As Object
      	Dim z As String
          
      	Set x = CreateObject("Outlook.Application")
      	Set y = x.CreateItem(0)
          
      	z = "Hello!" & vbNewLine & vbNewLine & _
          	"Hope you are well" & vbNewLine & _
          	"Visit our Exceldemy site"
          
      	On Error Resume Next
      	With y
          	.To = "Address"
          	.cc = ""
          	.BCC = ""
          	.Subject = "send mail based on cell value"
          	.Body = z
          	.Display
      	End With
      	On Error GoTo 0
          
      	Set y = Nothing
      	Set x = Nothing
      End Sub

      Please download the Excel file for solving your problem and practice with it.
      Send Email Automatically.xlsm
      If you are still facing issues, please mail us at the address below.
      [email protected]
      Again, thank you for being with us.
      Regards
      Md. Abdur Rahim Rasel
      Exceldemy Team

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo