How to jump to the cell with current date when open an Excel file

JJRed

New Member
Joined
Aug 2, 2018
Messages
2
Hi,

I have question regarding How to jump to the cell with current date when open an Excel file.

below are the links to my file.

https://drive.google.com/open?id=1_5H6x6pA53OcbOyvtpRfXm6oLVnT1vVa

I have tried using below VBA macro but it didn;t work.

Private Sub Workbook_Open()
Worksheets(“Sheet1”).Select
x = Day(Date)
Worksheets(“Sheet1”).Columns(2).Find(What:=x, LookIn:=xlValues).Activate
End Sub

Please advise.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try

Dim LastColNo As Long
Dim TodayDate As Long
Dim DateLoop As Long




Private Sub Workbook_Open()
LastColNo = Worksheets("Sheet1").Cells(4, Columns.Count).End(xlToLeft).Column
TodayDate = Now()


For DateLoop = 3 To LastColNo
If TodayDate = Worksheets("Sheet1").Cells(4, DateLoop).Value Then
Worksheets("Sheet1").Cells(4, DateLoop).Select
Exit For
End If
Next DateLoop
End Sub
 
Upvote 0
Hi - Welcome to the Board :)

I can't download your Workbook as I'm at work and file sharing sites are blocked, but I did notice you said you wanted to go to a cell with the current date?

In your code the variable x will resolve to 2.

Is that the value you're looking for or is it a proper date you have in your cells? (2 wont match to 2/8/2018)
 
Upvote 0
Try

Dim LastColNo As Long
Dim TodayDate As Long
Dim DateLoop As Long




Private Sub Workbook_Open()
LastColNo = Worksheets("Sheet1").Cells(4, Columns.Count).End(xlToLeft).Column
TodayDate = Now()


For DateLoop = 3 To LastColNo
If TodayDate = Worksheets("Sheet1").Cells(4, DateLoop).Value Then
Worksheets("Sheet1").Cells(4, DateLoop).Select
Exit For
End If
Next DateLoop
End Sub

When I open the file it jumps not on the current date but on the next date.

Please advise
 
Upvote 0
Have to say, I have no idea why this would happen
 
Upvote 0
How about
Code:
Private Sub Workbook_Open()
   Dim Fnd As Range
   
   Set Fnd = Sheets("Sheet1").Range("B4:AV4").Find(Format(Date, "dd mmm yy"), , xlValues, , , , , , False)
   If Not Fnd Is Nothing Then Application.Goto Fnd, True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top