Hi, I make macro to send automatic mail when in column there are different number. I would like to upgrade this macro and add one condition to send mail.
This is all condition to send my mail.
IF column 21 = 31 or 18 or 36 or 34 or 99 and Column 24 = not empty => send mail
IF column 25 = 31 or 18 or 36 or 34 or 99 and Column 28 = not empty => send mail
IF column 29 = 31 or 18 or 36 or 34 or 99 and Column 32 = not empty => send mail
IF column 33 = 31 or 18 or 36 or 34 or 99 and Column 36 = not empty => send mail
I tried with this one but is working only when all column are not empty. But I need just condition as write above.
Any idea?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim TablCode
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
TablCode = Array(31, 34, 36, 18, 99)
TablTargetColumns Array(21, 25, 29, 33)
TablNoemptyColumns Array(24, 28, 32, 36)
notEmpty = False
For Each c In TablNoemptyColumns
If Not IsEmpty(Target.Parent.Cells(Target.Row, c).Value) Then
notEmpty = True
Exit For
End If
Next
If InStr(Join(TablTargetColumns, " ") & " ", Target.Column & " ") > 0 And _
InStr(Join(TablCode, " ") & " ", Target.Value & " ") > 0 And _
notEmpty Then
'Macro email
'--------------------------------------------------------
If OutlookOuvert = False Then o = Shell("Outlook", vbNormalNoFocus)
Email_Subject = " DL " & TablCode(I)
Email_Send_From = "[email protected]"
Email_Send_To = "[email protected]"
Email_Cc = "[email protected]"
Email_Bcc = "[email protected]"
Email_Body = "Auto-mail" & vbCr & _
"" & vbCr & _
"Un code " & " a été attribué aujourd'hui" & vbCr & _
vbCr & _
"Date : " & Cells(Target.Row, 1) & vbCr & _
"Nom agent: " & Cells(Target.Row, 2) & vbCr & _
"Vol Départ: " & Cells(Target.Row, 13) & vbCr & _
"STD: " & Format(Cells(Target.Row, 18), "hh:mm") & vbCr & _
"ATD: " & Format(Cells(Target.Row, 19), "hh:mm") & vbCr & vbCr & _
"DR1: " & Cells(Target.Row, 21) & vbCr & _
"Time: " & Format(Cells(Target.Row, 23), "hh:mm") & vbCr & _
"Explication: " & Cells(Target.Row, 24) & vbCr & vbCr & _
"DR2: " & Cells(Target.Row, 25) & vbCr & _
"Time: " & Format(Cells(Target.Row, 27), "hh:mm") & vbCr & _
"Explication: " & Cells(Target.Row, 28) & vbCr & vbCr & _
"DR3: " & Cells(Target.Row, 29) & vbCr & _
"Time: " & Format(Cells(Target.Row, 31), "hh:mm") & vbCr & _
"Explication: " & Cells(Target.Row, 32) & vbCr & vbCr & _
"DR4: " & Cells(Target.Row, 33) & vbCr & _
"Time: " & Format(Cells(Target.Row, 35), "hh:mm") & vbCr & _
"Explication: " & Cells(Target.Row, 36) & vbCr & vbCr & _
"@TT"
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.send
End With
debugs:
If Err.Description <> "" Then MsgBox Err.Description
'----------------------------------------------------------------
End If
End Sub
Bookmarks