Email to be sent when a content is entered in a cell

Copper Contributor

Hello guys,

 

I would like to receive an automated email when a person enters a data in a specific cell of a spreadsheet. Is that possible? 

 

Thank you :)

4 Replies

@DanielaBarros88 

it is possible to set up an automated email notification when a specific cell in an Excel spreadsheet is updated. You can achieve this using a combination of Excel's Worksheet Change event and Outlook VBA (Visual Basic for Applications) code. Here's a step-by-step guide:

Enable Developer Tab:

  1. Open Excel and go to the "File" tab.
  2. Click on "Options."
  3. In the Excel Options dialog box, select "Customize Ribbon."
  4. Check the "Developer" option and click "OK."

Open the VBA Editor:

  1. Click on the "Developer" tab in the Ribbon.
  2. Click on "Visual Basic" to open the VBA Editor.

Write VBA Code:

Paste the following VBA code into the code window for the sheet where you want to monitor changes. Replace the email address and other details with your actual information.

vba code (is untested):

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim WatchRange As Range
    Dim IntersectRange As Range
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    
    ' Define the range to watch for changes
    Set WatchRange = Range("A1") ' Change A1 to the cell you want to monitor
    
    ' Check if a change occurred in the watch range
    If Not Intersect(Target, WatchRange) Is Nothing Then
        ' Create Outlook objects
        Set OutlookApp = CreateObject("Outlook.Application")
        Set OutlookMail = OutlookApp.CreateItem(0)
        
        ' Build the email
        With OutlookMail
            .To = "email address removed for privacy reasons" ' Replace with the recipient's email address
            .Subject = "Cell Value Updated"
            .Body = "The value in cell A1 has been updated to: " & WatchRange.Value
            ' You can customize the email body as needed
            .Send
        End With
        
        ' Release Outlook objects
        Set OutlookMail = Nothing
        Set OutlookApp = Nothing
    End If
End Sub

Test the Code:

  1. Change the recipient's email address and customize the email body as needed.
  2. Close the VBA Editor.
  3. Enter data into the specified cell (e.g., A1) to trigger the email.

Important Note:

  • Keep in mind that VBA code will only run if macros are enabled in your Excel settings. Some organizations may have security policies that restrict the execution of macros.
  • The email will be sent from the default Outlook profile on the computer where the code is running.
  • This solution assumes you have Outlook installed and configured on your computer.

Please be aware of the potential security implications when using VBA code, especially if the spreadsheet is shared or distributed. The text was created with the help of AI.

 

My answers are voluntary and without guarantee!

 

Hope this will help you.

 

Was the answer useful? Mark as best response and like it!

This will help all forum participants.