Consulting

Results 1 to 5 of 5

Thread: Search for todays date

  1. #1

    Search for todays date

    I've had real good luck here so I'll try one more.

    H12 to H403 contain dates. I would like to have a command button bring me to the current date. :sumo:


    I started by recording a macro to get me some of the code. But I'm not having much luck.

    Thanks

    Jeff

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try the following. If you need to refine it only to the listed cells, let me know.
    MD


    Sub FindDate()
        MyDate = Int(Now())
        Cells.Find(What:=MyDate, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Jeff,

    I guess you could arrange to record something which would work but it might be a bit convoluted. You could record something which you could quite easily edit to work. But probably the simplest way is not recordable ..

    Sub GoToToday()
        Range("H12:H403").Find(Date).Select
    End Sub
    To attach it to a button use ..

    Tools > Customize... > Commands tab
    Under Categories, select Macros
    Drag Custom Button to where you want it on your toolbar
    Right click on it and select Assign Macro - and assign your new macro (above)
    Right click again (as often as you want) to change other properties of the button
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi,

    I would only add one thing to Tony's code in case of error ...


    Option Explicit
    Sub GoToToday()
        Dim rngDate As Range
        Set rngDate = Range("H12:H403").Find(Date)
        If Not rngDate Is Nothing Then rngDate.Select
    End Sub

  5. #5
    Boy that was quick. And it works!. I have learned alot in the last few days. thanks for all the help!. I'm sure I'll think of a few more thing in the near future that I'd like to learn.

    Jeff

Posting Permissions

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