Re: "countdown"
Option Explicit
Sub FindMethod_SearchDate()
'Search for a date within a range
'user enters the date he wants to find in Range ("A")
'user wants to find the date in search Range ("A1:A30")
Dim rngFound As Range, rngSearch As Range, rngLast As Range
Dim strDate As String
'search range to find the date:
Set rngSearch = ActiveSheet.Range("A1:A30")
Set rngLast = rngSearch.Cells(rngSearch.Cells.Count)
'set variable for current date
strDate = Date
'CDate converts a number or text string to a Date data type. CDate(40200) returns "1/22/2010"; CDate("October 15, 2009") returns "10/15/2009"; CDate("2:25:15 PM") returns "2:25:15 PM"; CDate("hello") returns an error.
Set rngFound = rngSearch.Find(What:=CDate(strDate), After:=rngLast, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not rngFound Is Nothing Then
'return range address ($A$5 - in this example) if date is found:
MsgBox "Sending emails. "
'<-- place call to your email macro here.
Else
'if date is not found in search range:
MsgBox "Nothing to email. "
Exit Sub
End If
End Sub
Re: Which email to send based on date ... look at this:
http://stackoverflow.com/questions/3...-based-on-date
Here's what I think could be a solid start. You'll obviously have to resolve what email address the message should be sent to and how to format the body and whatnot.
The range given to r was based on the sample data you provided, which occupied A2-A4, but change this to whatever is correct.
Option Explicit
Sub email()
Dim r As Range
Dim cell As Range
Set r = Range("A2:A4")
For Each cell In r
If cell.Value = Date Then
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "subject"
Email_Send_From = "bob@bob.com"
Email_Send_To = "bob@bob.com"
Email_Cc = "bob@bob.com"
Email_Bcc = "bob@bob.com"
Email_Body = "body"
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
End If
Next
Exit Sub
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub
Bookmarks