Hey there, I am trying to check a user input to see if the user has entered the date correctly.
I am using the code below but it keeps giving me a "Type Mismatch" error. Does anyone know where I am going wrong?
Sub remove_old_data()
Dim dateDim As String
Do While (date_check(dateDim) = 1)
dateDim = InputBox(Prompt:="Please enter the date you wish to filter from: ", _
Title:="Date Filter", Default:="Date filter")
Loop
End Sub
Function date_check(datePar As String)
If (Format(datePar) <> Format(CDate(datePar), "DD/MM/YYYY")) Then 'checks if the format of the cell is equivalent to "DD/MM/YYYY", as required for import
MsgBox "Please enter the date in the format ""DD/MM/YYYY"".", vbInformation, "Remove Old Data"
'highlights in which cell the error took place
date_check = 1 'returns a 1 to indicate an error has occured
Exit Function 'exits the function
Else
date_check = 0
End If
End Function
Any help would be greatly appreciated, thanks.
Jag
Bookmarks