How? to go to cell when opening file

D

dpj

I have a column containing dates of the year. How can the file be opened
to go to the cell containing todays date?
 
B

Bob Phillips

Here's some code that goes into the ThisWorkbook code module

Private Sub Workbook_Open()
Dim oFoundCell As Range

With ActiveSheet.Range("A1:A100")
Set oFoundCell = .Find(what:=Date, _
LookIn:=xlFormulas)
If Not oFoundCell Is Nothing Then
oFoundCell.Activate
End If
End With

End Sub


Change the range to suit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

dpj

Thank you for that Bob.
I had a bit of trouble to start with but after changing line:-
Set oFoundCell = .Find(what:=Date, LookIn:=xlFormulas)
to
Set oFoundCell = .Find(Date, LookIn:=xlFormulas) I found it worked.

Can the code be modified to select the correct sheet if there are more
than one, eg. 2003,2004,2005 etc.?
 
B

Bob Phillips

This should do it

Private Sub Workbook_Open()
Dim oFoundCell As Range
Dim sYear As String

sYear = CStr(Year(Date))
Worksheets(sYear).Activate
With ActiveSheet.Range("A1:A100")
Set oFoundCell = .Find(what:=Date, _
LookIn:=xlFormulas)
If Not oFoundCell Is Nothing Then
oFoundCell.Activate
End If
End With

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top