T
Taurus
Hello,
I have problem in deleting the specific cell that has date format. The
cell has date format set in the spreadsheet. For example - 28-Apr-2005
Basically, I would like to delete the cell when user enter the wrong
value. For example: 666
But for some reason it doesn't allow me to delete the cells. And the
cell is not password protected and user allow to edit the field.
I used the syntax - selection.clearcontents
But it doesn't work. Did anyone has the same issue?
I build this function in a module. In the spreadsheet, when user enter
the value that is not the date format it should prompt the error
message and clear the cell contents.
Any Idea? Thank you in advanced
Public Function ValidateDate(vDate As Variant) As Boolean
On Error Resume Next
Do
If vDate = "" Then
ValidateDate = False
Exit Do
End If
If VBA.Year(vDate) <= 1980 Then
MsgBox "Please Enter the Test Date in yyyy-mm-dd format"
Sheet5.Activate
Range("D15").Select
Selection.ClearContents
ValidateDate = False
Exit Do
End If
If VBA.IsDate(vDate) Then
ValidateDate = True
Exit Do
Else
ValidateDate = False
MsgBox "Please Enter the Test Date in yyyy-mm-dd format"
Sheet5.Activate
Sheet5.Range("D15").Select
Selection.ClearContents
Exit Do
End If
Loop
End Function
I have problem in deleting the specific cell that has date format. The
cell has date format set in the spreadsheet. For example - 28-Apr-2005
Basically, I would like to delete the cell when user enter the wrong
value. For example: 666
But for some reason it doesn't allow me to delete the cells. And the
cell is not password protected and user allow to edit the field.
I used the syntax - selection.clearcontents
But it doesn't work. Did anyone has the same issue?
I build this function in a module. In the spreadsheet, when user enter
the value that is not the date format it should prompt the error
message and clear the cell contents.
Any Idea? Thank you in advanced
Public Function ValidateDate(vDate As Variant) As Boolean
On Error Resume Next
Do
If vDate = "" Then
ValidateDate = False
Exit Do
End If
If VBA.Year(vDate) <= 1980 Then
MsgBox "Please Enter the Test Date in yyyy-mm-dd format"
Sheet5.Activate
Range("D15").Select
Selection.ClearContents
ValidateDate = False
Exit Do
End If
If VBA.IsDate(vDate) Then
ValidateDate = True
Exit Do
Else
ValidateDate = False
MsgBox "Please Enter the Test Date in yyyy-mm-dd format"
Sheet5.Activate
Sheet5.Range("D15").Select
Selection.ClearContents
Exit Do
End If
Loop
End Function