+ Reply to Thread
Results 1 to 7 of 7

Search Worksheet For dates older than 30 days and Email Report to Admin

Hybrid View

excelSet Search Worksheet For dates... 12-04-2013, 12:18 PM
excelSet Re: Search Worksheet For... 12-09-2013, 03:56 PM
excelSet Re: Search Worksheet For... 12-11-2013, 10:12 AM
excelSet Re: Search Worksheet For... 12-13-2013, 01:12 PM
excelSet Re: Search Worksheet For... 12-16-2013, 05:00 PM
VBA FTW Re: Search Worksheet For... 12-16-2013, 05:22 PM
excelSet Re: Search Worksheet For... 12-17-2013, 11:17 AM
  1. #1
    Registered User
    Join Date
    09-14-2012
    Location
    New York, United States
    MS-Off Ver
    Excel 2010
    Posts
    10

    Search Worksheet For dates older than 30 days and Email Report to Admin

    Hello again all, I'm back with another question! Last time you guys were awesome with helping me find a solution, so I hope this question is just as easy for you excel pros.

    Ok, so what i'm trying to accomplish is set up a VBA macro that automatically emails me with a list of rows where every row has a Date column that is older than 30 day. I have already accomplished getting the email part to work, based off of examples and help threads from the web and this forum as well. My problem is the Body part of the email. I am having trouble with what I need to include in the module that searches the entire 'F' Column (Expiration Date) and where that date is older than 30 days, it takes the User Name from Column A + the NickName from Column B + the Expiratoin Date from Column F and appends that data to the string that is later used in the "body" part of the email.



    Headers From Excel Worksheet (Column Names)
    USER: Nickname/Comment: MAC Addresses: # Users: Close? Expiration Date:



    Excel Module Code:
    Option Explicit
    
    Const strTo As String = "myEmail@address.com"
    Const strCC As String = ""  '<~~ "" if you do not want to CC
    Const strBCC As String = "" '<~~ "" if you do not want to BCC
    Sub Sample()
        Dim OutApp As Object, OutMail As Object
        Dim strbody As String, strSubject As String
        Dim strbodyStart As String, strbodyEnd As String
    
    
        strSubject = "!Important - Expiring Licenses Report"
                            
        strbodyStart = ""
        strbody = ""
        strbodyEnd = ""
        On Error Resume Next
        strbodyStart = "Message Start" & vbCrLf
        strbody = Application.WorksheetFunction. _
            Date(Range("F3:F").Value <= Date - 30) & vbCrLf
        strbodyEnd = "Message End" & vbCrLf
        On Error GoTo 0
        
    
        Set OutApp = CreateObject("Outlook.Application")
    
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = strTo
            .CC = strCC
            .BCC = strBCC
            .Subject = strSubject
            .Body = strbodyStart & strbody & strbodyEnd
            .Send
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub

    Sample Of What The Email Should Look Like:
    User 1 Bob 11/12/2012
    User 2 Carl 11/12/2012
    User 3 Sam 11/12/2012
    User 4 Tony 11/12/2012
    User 5 Russell 11/12/2012



    Thanks in advance for all your help!

  2. #2
    Registered User
    Join Date
    09-14-2012
    Location
    New York, United States
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Search Worksheet For dates older than 30 days and Email Report to Admin

    Bump no response.

    If I have not provided enough details, please let me know and I shall try my best to give you as much information as I can.

    Thanks.

  3. #3
    Registered User
    Join Date
    09-14-2012
    Location
    New York, United States
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Search Worksheet For dates older than 30 days and Email Report to Admin

    Bump no response.

  4. #4
    Registered User
    Join Date
    09-14-2012
    Location
    New York, United States
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Search Worksheet For dates older than 30 days and Email Report to Admin

    Bump no response.

  5. #5
    Registered User
    Join Date
    09-14-2012
    Location
    New York, United States
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Search Worksheet For dates older than 30 days and Email Report to Admin

    Bump no response. Still looking for a solution.

  6. #6
    Forum Contributor
    Join Date
    07-26-2012
    Location
    USA
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    351

    Re: Search Worksheet For dates older than 30 days and Email Report to Admin

    Sub Sample()
        Dim OutApp As Object, OutMail As Object
        Dim strbody As String, strSubject As String
        Dim strbodyStart As String, strbodyEnd As String
    
    
        strSubject = "!Important - Expiring Licenses Report"
                            
        strbodyStart = ""
        strbody = ""
        strbodyEnd = ""
        On Error Resume Next
        strbodyStart = "Message Start" & vbCrLf
        strbodyEnd = "Message End" & vbCrLf
        On Error GoTo 0
        
            Dim c
            For Each c In Sheets("Sheet1").Range("F3:F10")
             If CDate(c) <= (Date - 30) Then
                strbody = strbody & vbNewLine & Sheets("Sheet1").Range("A" & c.Row) & " " & Sheets("Sheet1").Range("B" & c.Row) & " " & c & vbNewLine            
             End If
            Next c
    
        Set OutApp = CreateObject("Outlook.Application")
    
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
        With OutMail
            .To = strTo
            .CC = strCC
            .BCC = strBCC
            .Subject = strSubject
            .Body = strbody
            '.Body = strbodyStart & strbody & strbodyEnd
            .Display
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
        
    
    End Sub
    Here you go


    But pay attention to this
    Range("F3:F10")
    You'll need to change this to fit your range, or add a line of code to find the last used row in column F.
    Last edited by VBA FTW; 12-16-2013 at 05:25 PM.

  7. #7
    Registered User
    Join Date
    09-14-2012
    Location
    New York, United States
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Search Worksheet For dates older than 30 days and Email Report to Admin

    Thank you so much VBA FTW! It works beautifully. +1 to you.

+ 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. Search multiple columns of dates and send reminder email 30 days before expiry
    By prh2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2013, 12:47 AM
  2. [SOLVED] Comparing dates 4 days older or more
    By dlamberth in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-11-2013, 07:03 PM
  3. Count number of dates older than 30 days
    By altaquip_travis in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-12-2008, 03:20 PM
  4. [SOLVED] formula to find and flag dates older than 30 days
    By Will G. in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2005, 08:05 PM
  5. [SOLVED] Dates older than 29 days
    By ab in forum Excel General
    Replies: 2
    Last Post: 06-16-2005, 05:05 PM

Tags for this Thread

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