Scroll down to today's date

pontiff

Board Regular
Joined
Jun 11, 2009
Messages
150
Office Version
  1. 2016
Hi,
I'm using the following script from another thread to try to have my worksheet (sheet1) scroll down to the row containing today's date on opening.

Private Sub Workbook_Open()
Worksheets(“Sheet1”).Select
x = Format(Date, "dd/mm/yyyy")
On Error Resume Next
Worksheets(“Sheet1”).Columns(2).Find(What:=x, LookIn:=xlValues).Activate
Application.Goto Selection, True
End Sub

My dates are in column B as dd/mm/yyyy .

It seems to select the correct date (green box appears around 06/03/2018) but doesn't scroll down/up to it.
Any advice much appreciated.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Code:
Private Sub Workbook_Open()
    Worksheets(“Sheet1”).Select
    x = Format(Date, "dd/mm/yyyy")
    'On Error Resume Next
    Worksheets(“Sheet1”).Columns(2).Find(What:=x, LookIn:=xlValues).Activate
    Application.Goto Selection, True

    ActiveWindow.ScrollRow = Selection.Row
    ActiveWindow.ScrollColumn = Selection.Column
End Sub
 
Upvote 0
Code:
Private Sub Workbook_Open()
    Worksheets(“Sheet1”).Select
    x = Format(Date, "dd/mm/yyyy")
    'On Error Resume Next
    Worksheets(“Sheet1”).Columns(2).Find(What:=x, LookIn:=xlValues).Activate
    Application.Goto Selection, True

    ActiveWindow.ScrollRow = Selection.Row
    ActiveWindow.ScrollColumn = Selection.Column
End Sub

Thanks for the reply, I still cant get it to work. To enter the code I'm right clicking on "Sheet1", selecting view code and pasting it there. Is there something I'm doing wrong?
 
Upvote 0
Thanks for the reply, I still cant get it to work. To enter the code I'm right clicking on "Sheet1", selecting view code and pasting it there. Is there something I'm doing wrong?
Yes. Workbook_Open event procedure code needs to go in the "ThisWorkbook" module, not in any of the Sheet modules.
 
Upvote 0
Yes. Workbook_Open event procedure code needs to go in the "ThisWorkbook" module, not in any of the Sheet modules.

Thanks. I've moved it now but am getting a "Runtime error 9 subscript out of range" error on this line....

Worksheets(“Sheet1”).Select
 
Upvote 0
Thanks. I've moved it now but am getting a "Runtime error 9 subscript out of range" error on this line....

Worksheets(“Sheet1”).Select
VBA is very picking and does not like slanted or curvy double-quote marks.
Try:
Code:
Worksheets("Sheet1").Select
 
Upvote 0
VBA is very picking and does not like slanted or curvy double-quote marks.
Try:
Code:
Worksheets("Sheet1").Select


Thanks for your patience so far! I've now got the code like this (I've changed sheet name in code and sheet)

Private Sub Workbook_Open()
Worksheets("Payments").Select
x = Format(Date, "dd/mm/yyyy")
'On Error Resume Next
Worksheets("Payments").Columns(2).Find(What:=x, LookIn:=xlValues).Activate
Application.Goto Selection, True


ActiveWindow.ScrollRow = Selection.Row
ActiveWindow.ScrollColumn = Selection.Column
End Sub

I'm now getting a "object variable or With block variable not set" for the line highlighted above in red.
 
Upvote 0
Are your dates in column B entered as dates or text?
Note that this calculation:
Code:
[COLOR=#333333]x = Format(Date, "dd/mm/yyyy")[/COLOR]
returns a text entry, not a date one

If your entry is really a date, try this instead:
Code:
x = Date
 
Upvote 0
Are your dates in column B entered as dates or text?
Note that this calculation:
Code:
[COLOR=#333333]x = Format(Date, "dd/mm/yyyy")[/COLOR]
returns a text entry, not a date one

If your entry is really a date, try this instead:
Code:
x = Date


That's it! Thank you very much. Many hours of scrolling time saved! :)
Thanks to all for the replies.
 
Upvote 0
You are welcome!
Glad we could help.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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