Hi everyone.
I have a form in which the user inputs some data, including the date.
When the user clicks on a button, I'm using the Range.Find function to find a cell in the range with the same date.
Now the function works fine, when the date is written in the cell as a long value, and the cell is not formatted as a cell that contains a date. (i.e. the cells value is 40598)
However, when I format the cell to show the date as "dd-mm-yy" instead of just the number (01-02-11) the find function doesn't work.
Can anyone help me?
Below is my code:
I have a form in which the user inputs some data, including the date.
When the user clicks on a button, I'm using the Range.Find function to find a cell in the range with the same date.
Now the function works fine, when the date is written in the cell as a long value, and the cell is not formatted as a cell that contains a date. (i.e. the cells value is 40598)
However, when I format the cell to show the date as "dd-mm-yy" instead of just the number (01-02-11) the find function doesn't work.
Can anyone help me?
Below is my code:
Code:
Dim worksheet
Dim findDate As Date
Dim convertDate As Long
Dim findRange As range
Set worksheet = Worksheets("expenses")
findDate = Me.date_input
convertDate = findDate
If (Trim(convertDate) <> "") Then
With worksheet.range("6:68")
Set findRange = .Find(What:=convertDate, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not findRange Is Nothing Then
Application.Goto findRange, True
Else
MsgBox("Date not present")
End If
End With
End If