PDA

View Full Version : Solved: Search for todays date



74Pumpkin
11-22-2004, 05:30 PM
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

mdmackillop
11-22-2004, 05:55 PM
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

TonyJollans
11-22-2004, 05:57 PM
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

Zack Barresse
11-22-2004, 06:20 PM
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

74Pumpkin
11-22-2004, 06:54 PM
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