Sending e-mail if conditions are met

NewbieMike

New Member
Joined
May 29, 2015
Messages
5
Hello, I am trying to set up a macro that automatically sends out an e-mail if the date in column b equals today and also if the first 10 characters in columns c equal [Fastlane]. I have multiple rows data so I would need it to check each row for the 2 criteria.

I can't figure out how to do this based on multiple columns and rows, can someone help please?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hello! Please try this solution.

First, place this code in the WORKSHEET where you want to evaluate for emailing criteria.

VBA Code:
Private Sub Worksheet_SelectionChange _
  (ByVal Target As Range)

Dim rngB    As Range
Dim rngC    As Range
Dim rngCell As Range
Dim str10   As String

Set rngCell = Target
Set rngB = Range("B" & rngCell.Row)
Set rngC = Range("C" & rngCell.Row)
str10 = VBA.UCase(VBA.Left(rngC.Text, 10))

If rngCell.Value = VBA.Date Then

  If str10 = "FASTLANE" Then
  
    Call Email("To", "Subject", "Text")
    
  End If

End If

Set rngB = Nothing
Set rngC = Nothing
Set rngCell = Nothing

End Sub

Next, in your code module, enter this code:

VBA Code:
Sub Email _
  (sTo As String, sSub As String, _
   sHTML As String, Optional sAttach As String, _
   Optional sAction As String = "Display", _
   Optional sCCs As String, Optional sFrom As String)


'Declare Variables
Dim olApp As Object
Dim olMsg As Object

'Create Email Message
Set olApp = CreateObject("Outlook.Application")
Set olMsg = olApp.CreateItem(0)

On Error Resume Next
   With olMsg
    
      If sFrom <> "" Then

          .SentOnBehalfOfName = sFrom

      End If
      
      .Display
      .To = sTo
      .CC = sCCs
      .HTMLBody = sHTML & .HTMLBody
      .Subject = sSub
      
      If sAttach <> "" Then

          .Attachments.Add sAttach

      End If
      
      If sAction = "Display" Then
      
         .Display
         
      ElseIf sAction = "Send" Then
      
         .Send
         
      End If
      
   End With
On Error GoTo 0

'Clear Set Variables
Set olApp = Nothing
Set olMsg = Nothing


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top