Button or form to go to specific date of today's date

Sacruzsa

New Member
Joined
Feb 28, 2022
Messages
29
Office Version
  1. 2019
Platform
  1. Windows
Hello everyone ,
At work a colleague has created a calendar for filling in the activity of all our personnel, now this is not user-friendly in my opinion because it is 1 elongated list for the whole year, it is also very annoying since if someone enters something in August and closes the excel, the next person arrives on this day so I wondered if it is possible to make a button or form in which 2 things should happen
1. Go to specific date in the sheet (search bar)
2. go to today
Is that possible , and how do I get started ?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You haven't said where your list of dates is so I have assumed it is column A going from row 1 to row 365
These two macros will do what you have asked for, you just need to create two buttons to trigger them. You can try just running them without the buttons to test them:
VBA Code:
Sub gotoday()
Dim tt As Long

Inarr = Range(Cells(1, 1), Cells(365, 1))
tt = Application.WorksheetFunction.RoundDown(Now(), 0)
For i = 1 To 365
If tt = Inarr(i, 1) Then
 Cells(i, 1).Select
 Exit For
End If
Next i

End Sub

Sub gotodate()
Dim tt As Long
Dim TheString As String, TheDate As Date
TheString = Application.InputBox("Enter A Date")
If IsDate(TheString) Then
    TheDate = DateValue(TheString)
Else
    MsgBox "Invalid date"
     Exit Sub
End If

Inarr = Range(Cells(1, 1), Cells(365, 1))
tt = TheDate
For i = 1 To 365
If tt = Inarr(i, 1) Then
 Cells(i, 1).Select
 Exit For
End If
Next i

End Sub
 
Upvote 0
You haven't said where your list of dates is so I have assumed it is column A going from row 1 to row 365
These two macros will do what you have asked for, you just need to create two buttons to trigger them. You can try just running them without the buttons to test them:
VBA Code:
Sub gotoday()
Dim tt As Long

Inarr = Range(Cells(1, 1), Cells(365, 1))
tt = Application.WorksheetFunction.RoundDown(Now(), 0)
For i = 1 To 365
If tt = Inarr(i, 1) Then
 Cells(i, 1).Select
 Exit For
End If
Next i

End Sub

Sub gotodate()
Dim tt As Long
Dim TheString As String, TheDate As Date
TheString = Application.InputBox("Enter A Date")
If IsDate(TheString) Then
    TheDate = DateValue(TheString)
Else
    MsgBox "Invalid date"
     Exit Sub
End If

Inarr = Range(Cells(1, 1), Cells(365, 1))
tt = TheDate
For i = 1 To 365
If tt = Inarr(i, 1) Then
 Cells(i, 1).Select
 Exit For
End If
Next i

End Sub
Hello Offthelip

The given code doesn't work for going to today's date I used the code below:

Sub Select_Today()
Cells.Find(Date, , xlValues, xlWhole).Select
End Sub

For the code 'Search for date' I probably have to enter the correct cells and rows but I have already entered everything and nothing works, the part to enter a date works but nothing happens when I enter a date, also no error message
In the image below you can see which cells are used, hopefully you can help me further

1663677845332.png
 
Upvote 0
Read the first sentence of my post that is why it doesn't work. I am not at a computer at the moment and not able ti write code
 
Upvote 0
Read the first sentence of my post that is why it doesn't work. I am not at a computer at the moment and not able ti write code
Yes I have read that , the problem is that I do not know what to enter at all , I have already tried everything with an error code as a result
 
Upvote 0
I am now back at a PC, so I assume from your picture that the dates are in row 4 , so try this:
VBA Code:
Sub gotoday()
Dim tt As Long

Inarr = Range(Cells(4, 1), Cells(4, 365))
tt = Application.WorksheetFunction.RoundDown(Now(), 0)
For i = 1 To 365
If tt = Inarr(1, i) Then
 Cells(4, i).Select
 Exit For
End If
Next i

End Sub

Sub gotodate()
Dim tt As Long
Dim TheString As String, TheDate As Date
TheString = Application.InputBox("Enter A Date")
If IsDate(TheString) Then
    TheDate = DateValue(TheString)
Else
    MsgBox "Invalid date"
     Exit Sub
End If

Inarr = Range(Cells(4, 1), Cells(4, 365))
tt = TheDate
For i = 1 To 365
If tt = Inarr(1, i) Then
 Cells(4, i).Select
 Exit For
End If
Next i

End Sub
 
Upvote 0
Solution
I am now back at a PC, so I assume from your picture that the dates are in row 4 , so try this:
VBA Code:
Sub gotoday()
Dim tt As Long

Inarr = Range(Cells(4, 1), Cells(4, 365))
tt = Application.WorksheetFunction.RoundDown(Now(), 0)
For i = 1 To 365
If tt = Inarr(1, i) Then
 Cells(4, i).Select
 Exit For
End If
Next i

End Sub

Sub gotodate()
Dim tt As Long
Dim TheString As String, TheDate As Date
TheString = Application.InputBox("Enter A Date")
If IsDate(TheString) Then
    TheDate = DateValue(TheString)
Else
    MsgBox "Invalid date"
     Exit Sub
End If

Inarr = Range(Cells(4, 1), Cells(4, 365))
tt = TheDate
For i = 1 To 365
If tt = Inarr(1, i) Then
 Cells(4, i).Select
 Exit For
End If
Next i

End Sub
Offthelip,
Now it works perfectly, both buttons do what they should, I can't thank you enough
thank you for the assistance
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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