Making sure a cell has a date in it

z0de

Board Regular
Joined
Oct 22, 2010
Messages
75
What code could I use in vba to make sure a user has inputted a date in a cell?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
HI

See this from VBA help in Excel.


<TABLE id=topTable width="100%"><TBODY><TR id=headerTableRow2><TD align=left>IsDate Function</TD></TR></TBODY></TABLE>
Returns a Boolean value indicating whether an expression can be converted to a date.
Syntax
IsDate(expression)
The required expression argument is a Variant containing a date expression or string expression recognizable as a date or time.
Remarks
IsDate returns True if the expression is a date or is recognizable as a valid date; otherwise, it returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the ranges vary among operating systems.
Example

This example uses the IsDate function to determine if an expression can be converted to a date.
<TABLE><TBODY><TR><TD>
<CODE>Dim MyDate, YourDate, NoDate, MyCheckMyDate = "February 12, 1969": YourDate = #2/12/69#: NoDate = "Hello"MyCheck = IsDate(MyDate) ' Returns True.MyCheck = IsDate(YourDate) ' Returns True.MyCheck = IsDate(NoDate) ' Returns False.</CODE></PRE></TD></TR></TBODY></TABLE>
<xml>ofm</xml>© 2010 Microsoft Corporation. All rights reserved.
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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