Results 1 to 6 of 6

vba function today()

This is a discussion on vba function today() within the Excel Questions forums, part of the Question Forums category; dear all i have date in 3 columns ,A,B AND C. In columns A i have the name and Columns ...

  1. #1
    Board Regular
    Join Date
    Jul 2010
    Posts
    665

    Question vba function today()

    dear all

    i have date in 3 columns ,A,B AND C. In columns A i have the name and Columns C i have the birhday date in 2010, the data is a per below

    namebirthdaythis year birthday
    ziad27/11/7827/11/10
    Mazen05/12/8005/12/10
    Maxwel06/07/6306/07/10
    John14/02/7314/02/10


    i need a vba code that will loop through the column C and if it is equal to todays date, it shoud give me a messagebox, note that i may have more than one birthday in the same date.

    appreciate any assistance.

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    14,601

    Default Re: vba function today()

    Try...

    Code:
    Option Explicit
    
    Sub test()
    
        Dim LastRow As Long
        Dim i As Long
        Dim Msg As String
    
        LastRow = Cells(Rows.Count, "C").End(xlUp).Row
        
        For i = 2 To LastRow
            If Cells(i, "C").Value = Date Then
                Msg = Msg & Cells(i, "A").Value & vbNewLine
            End If
        Next i
        
        MsgBox Msg, vbInformation
        
    End Sub
    Domenic Tamburino
    Microsoft MVP - Excel
    xl-central.com - "For Your Microsoft Excel Solutions"

  3. #3
    Board Regular
    Join Date
    Mar 2008
    Posts
    2,638

    Default Re: vba function today()

    Perhaps this will work for you:
    Code:
    Sub bday()
    Dim ce As Range, LR As Long
    LR = Range("C" & Rows.Count).End(xlUp).Row
    For Each ce In Range("C2:C" & LR)
        If ce.Value = Date Then result = result & ce.Offset(0, -2).Value & vbCrLf
    Next ce
    MsgBox "Today is the birthday of:" & vbCrLf & result
    End Sub
    Where to upload Excel files so threads don't take 20+ posts to get the correct answer from guessing:

    MediaFire: http://www.mediafire.com/
    FileFactory: http://www.filefactory.com/

    Also, in your thread or in your signature TELL US WHAT VERSION OF EXCEL YOU'RE USING!!!

    I'm using Excel 2007. My solutions will be appropriate for that version unless you tell us otherwise.

  4. #4
    Board Regular
    Join Date
    Jul 2010
    Posts
    665

    Question Re: vba function today()

    thanks , it works.

    is there a way to write a macro for a workbook to open on its own, lets say 8:30 in the morning.

  5. #5
    Board Regular
    Join Date
    Mar 2008
    Posts
    2,638

    Default Re: vba function today()

    Yes, but start a new thread. Since code to do that is readily available on hundreds of sites on the internet (including this one), you may want to do a Google search first.
    Where to upload Excel files so threads don't take 20+ posts to get the correct answer from guessing:

    MediaFire: http://www.mediafire.com/
    FileFactory: http://www.filefactory.com/

    Also, in your thread or in your signature TELL US WHAT VERSION OF EXCEL YOU'RE USING!!!

    I'm using Excel 2007. My solutions will be appropriate for that version unless you tell us otherwise.

  6. #6
    Board Regular
    Join Date
    Jul 2010
    Posts
    665

    Smile Re: vba function today()

    you are right thanks.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com