gotoToday macro not working, please help

sumhungl0

Board Regular
Joined
Jan 1, 2014
Messages
119
good afternoon,
i have a xlsm file that has a button to find the cell with todays date and scroll to it. the sheet is a rolling calendar with dates across the top/columns (1:1). the button has worked for 5+ years and is still working. now i am recreating the sheet for something else but the same code does not work. it gives me run-time error '91': object variable or with block variable not set, and i have no clue why this wont work on a freshly created workbook but still works on the original. i am using excel 2013. i threw a few msgbox lines in to test to see if the code would find the date but i dont think it is finding the date at all. i went back and made sure the cells are formated to be a date and still nothing. am i missing a reference or something? i cant figure this out. can someone please help? thank you and have a great day.

here is the code i have:
Code:
Sub GoToToday() 'scroll to today'Cells.Find(Date, , xlValues, xlWhole).Select
Columns(1).Find(Date, , xlValues).Select
ActiveWindow.ScrollColumn = ActiveCell.Column
End Sub

i have also tried the following codes i found during my search for a fix:
Code:
Sub scrollToday()
With Range("1:1")
Set c = .Find(DateValue(Now()), LookIn:=xlValues)
If Not c Is Nothing Then
MsgBox .Address
.Select
ActiveWindow.ScrollColumn = c.Column
End If
End With
End Sub
Sub Find_Todays_Date()
Dim FindString As Date
Dim rng As Range
FindString = Date
With Sheets("Sheet1").Range("1:1")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumn, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
Else
MsgBox "Nothing found"
End If
End With
End Sub
Sub tryme()
LastCol = Cells(Columns.Count, "1").End(xlPrevious).Column
For j = 1 To LastCol
 If Cells(j, "1").Value = Date Then
   Cells(j, "1").Select
   Exit For
 End If
Next j
End Sub
Sub findToday()
    Dim sht As Worksheet
    Dim rng As Range
    Dim r As Range


    Set sht = ThisWorkbook.Worksheets("MOF")
    Set rng = sht.Range("1:1")
    
    Set r = rng.Find(Date)
    MsgBox r.Address
    If Not r Is Nothing Then r.Select
End Sub
 
How about
Code:
Sub GoToToday()
Dim fnd As Range 
Set fnd = Range("1:1").find(Format(Date, "dd-mmm"), , , , , , , , False)
If Not fnd Is Nothing Then ActiveWindow.ScrollColumn = fnd.Column
End Sub
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
Code:
Sub GoToToday()
Dim fnd As Range 
Set fnd = Range("1:1").find(Format(Date, "dd-mmm"), , , , , , , , False)
If Not fnd Is Nothing Then ActiveWindow.ScrollColumn = fnd.Column
End Sub
same thing, did nothing, no error tho, dont think it is finding a date at all. thanks for the help.
 
Upvote 0
That worked for me on your test file.
 
Upvote 0
You should enter a proper date in Range("A1") like 3/1/18
And then drag it over to other cells.

Just because the cell is formatted to look like you want does not mean Excel sees it's as a date.
 
Last edited:
Upvote 0
maybe there are some restrictions on my work pc/network. lemme try to remake the file on my home pc. this is frustrating.
 
Upvote 0
You should enter a proper date in Range("A1") like 3/1/18
And then drag it over to other cells.

Just because the cell is formatted to look like you want does not mean Excel sees it's as a date.
when you type in 1mar, excel recognizes it as a date. i can then msgbox that cell and get the proper date or the excel date number. however when i looked at what excel auto formatted it to, it was custom.
 
Upvote 0
i just got this working with Fluff's code. i went back to the file i shared and formatted row 1 as dates. then i placed the code under the original and hit play. this time no error and it did scroll. what the hell is going on? i tried it at work too but i got nothing. i just got home from work, i will test this out tomorrow again. thanks for all the help you two. have a great night.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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