+ Reply to Thread
Results 1 to 2 of 2

Send Email to X if Target Cell equals Y

Hybrid View

  1. #1
    Registered User
    Join Date
    11-09-2015
    Location
    Peterborough
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Send Email to X if Target Cell equals Y

    Good Afternoon,

    My expertise of VBA is still intermediate so any help concerning this matter is much appreciated.

    I have created a VBA Script (As per Below) to send an email to an individual recipient however I'm finding it difficult to ascertain the means to send an email to a particular user depending on the data in a given cell.

    For instance if Target.Cell.Offset (0,-2).value = A then an email needs to be send to [email protected]

    There are 8 alternative variables, each of which given an alternative email address.

    Please see the below script.

    Please could someone provide me with a solution to this problem.

    Thank you in advance.

    Private Sub SendEmail(EmailSubject, EmailBody)
            Dim OutApp As Outlook.Application
            Dim OutMail As Outlook.MailItem
            Dim MyReci As Outlook.Recipient
            
            Set OutApp = New Outlook.Application
            Set OutMail = OutApp.CreateItem(olMailItem)
            
            With OutMail
                .Recipients.Add ("x")
                .Subject = Emailubject
                .Body = EmailBody
                .CC = ("[email protected]")
                .Display
            End With
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      
        If Target.Value = "" Then
            Target.Value = "ü"
            Target.Font.Name = "Wingdings"
        End If
                
        If Target.Cells.Offset(0, -2).Value = "Open" Then
             Answer = MsgBox("Distribute email?", vbYesNo, Cells(Target.Row, 3).Value)
        If Answer = vbYes Then
            EmailSubject = "PIR Task"
            EmailBody = Target.Cells.Offset(0, -13).Value & vbNewLine & vbNewLine & "ACTION: " & Target.Cells.Offset(0, -7) & vbNewLine & vbNewLine & "DUE DATE:" & Target.Cells.Offset(0, -5).Value
            SendEmail EmailSubject, EmailBody
            Else
        Exit Sub
        End If
    End If
    
    End Sub

  2. #2
    Forum Contributor
    Join Date
    06-30-2015
    Location
    Netherlands
    MS-Off Ver
    2013 / 2016 / 365
    Posts
    146

    Re: Send Email to X if Target Cell equals Y

    Hi,

    I don't have a full incorporated solution but have a look at this. perhaps it will help you in the right direction.

    Sub select_email_adres_from_list()
    
    '==> create an array with your list of email adresses
    
    Email_list = Array("[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]")
    
    '==> Use a case statement to check what's in your target cell and get the correct position in the array
    Select Case Range("P2").Value
              Case "A"
                  Range("B1").Value = 0
                  Counter = 0
              Case "B"
                  Range("B1").Value = 1
                  Counter = 1
              Case "C"
                  Range("B1").Value = 2
                  Counter = 2
              Case "D"
                  Range("B1").Value = 3
                  Counter = 3
              Case "E"
                  Range("B1").Value = 4
                  Counter = 4
              Case "F"
                  Range("B1").Value = 5
                  Counter = 5
              Case "G"
                  Range("B1").Value = 6
                  Counter = 6
              Case "H"
                  Range("B1").Value = 7
                  Counter = 7
        End Select
    '==> this will create a messagebox with the email adress as a result of the value in the target adress
    MsgBox (Email_list(Counter))
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Condition on sendint email or not to send email by a yes no in a cell
    By toofani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2015, 04:35 AM
  2. Workflow with signatures (if cell=x then send email, if signed then send email)
    By Kate2811 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2014, 05:37 AM
  3. How to send email from excel using VBA with Cell Range (Including Images) as Email Body
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 05:06 AM
  4. Using VBA to send Email by selecting email from a cell within a worksheet
    By sm.salford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2013, 01:58 PM
  5. Auto send email with the cell value that triggered the email in the first place.
    By coobey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2013, 05:40 PM
  6. Code to send email if cell value equals Today() - 10
    By plexic in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2012, 01:44 PM
  7. Send Email When Cell Value Changes
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-18-2006, 10:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1