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:
i have also tried the following codes i found during my search for a fix:
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