I am really new at VBA. Would someone be able to assist me. I am try to create an if else statement to trigger an email to contain values from certain cells.
My target is to have the email body to contain CaseNo (located from col C) and Case date (located in Col D) if a number more than 1 is keyed in any cell in Col R of that specific row.
example: C3 = 345, D3 = A and a number 2 is keyed into R3.
Below is the code I have so far. My current if else statement only able to retrieve the values in cell C1 and D1 only.
My target is to have the email body to contain CaseNo (located from col C) and Case date (located in Col D) if a number more than 1 is keyed in any cell in Col R of that specific row.
example: C3 = 345, D3 = A and a number 2 is keyed into R3.
Below is the code I have so far. My current if else statement only able to retrieve the values in cell C1 and D1 only.
VBA Code:
'Update by Extendoffice 2018/3/7
'code to check if cell range in col R is more than 0 then trigger email
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("R2 :R3000"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 0 Then
Call Mail_small_Text_Outlook
End If
'code to launch email app (outlook)
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
'Dim strbody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
'Code for email content
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"You have a query from: " & Range("E2,E2000") & vbNewLine & _
"Case Number: " & Range("c2,C3000") & Range("D2,D2000") & vbNewLine & _
"Thank you"
'Code to auto fill addressess's email address
On Error Resume Next
With xOutMail
.To = "[EMAIL]ssjdksjf@gmail.com[/EMAIL]"
.CC = ""
.BCC = ""
.Subject = "Pending query processing"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
End Sub
Last edited by a moderator: