FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,364
- Office Version
- 365
- 2016
- Platform
- Windows
I have a spreadsheet where column H:I will receive a date. All of this is done thru a DoubleClick event with calls the calendar function. All of this works well. Now I need to ensure the user does not simply enter something into the cell that is not a date. I've added a SheetChange event and it seems to be working well, but just curios if this is the proper way to do it? This DoubleClick event is happening on multiple sheets therefore in the ThisWorkbook module.
VBA Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
If Target.CountLarge > 1 Or Target.Row < 3 Then Exit Sub
If Sh.Range("A1").Value = "Unit" Then
If Not Intersect(Target, Sh.Range("H:I")) Is Nothing Then
Call AskFor_A_Date
End If
End If
End Sub
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.CountLarge > 1 Or Target.Row < 3 Then Exit Sub
Dim msg As String: msg = "Please double click in the cell and use the calendar to enter a date"
If Sh.Range("A1").Value = "Unit" Then
If Not Intersect(Target, Sh.Range("H:I")) Is Nothing Then
If Not IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.ClearContents
CreateObject("WScript.Shell").Popup msg, 1, "Enter Date"
Target.Select
Application.EnableEvents = True
End If
End If
End If
End Sub