DoubleClick event to enter date

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
Office Version
  1. 365
  2. 2016
Platform
  1. 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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Upvote 0
I'm not looking for any help with the code for the calendar, I was just asking about the Workbook change event. I'm asking the user to doubleclick on a cell to enter a date; however, there could be a user that tries to enter something into the cells versus doubleclicking. So say the user simple enters "April". We know that is just text and not a date. I want to tell the user that is not a date and instead to use the doubleclick event. The code about does exactly that. Erases what the user entered and shows a msgbox saying to use the doubleclick. I was just seeking some guidance on if there could be a better way to do this or is this sufficient.
 
Upvote 0
If hards to know if your doing this the best way when I have no ideal what the code is doing.
What is the Date Picker code doing?
 
Upvote 0
I'm not looking for any help with the code for the calendar, I was just asking about the Workbook change event. I'm asking the user to doubleclick on a cell to enter a date; however, there could be a user that tries to enter something into the cells versus doubleclicking. So say the user simple enters "April". We know that is just text and not a date. I want to tell the user that is not a date and instead to use the doubleclick event. The code about does exactly that. Erases what the user entered and shows a msgbox saying to use the doubleclick. I was just seeking some guidance on if there could be a better way to do this or is this sufficient.
OK. Understand
 
Upvote 0
The main problem I can see is if the user enters any old number your code will be happy.
You could lock the sheet to prevent users from manually entering info into those cells
 
Upvote 0
Hi Fluff,

How about if I just check the manually entered number to make sure it falls between today -/+ 365?
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,842
Members
449,193
Latest member
MikeVol

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