#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default date format

How can I set a date format for any cell and user has to use that format
otherwise user is not allowed to enter any date.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,480
Default date format

Hi

you can only do it with code.
The following is some event code which would ensure that only dates can be
entered in column A, strating from row 2.
Adjust to suit your nededs.
also, date format has been set as dd mmm yyyy e.g. 02 Jan 2010, again change
to suit the format you want.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim edate As Date
If Target.Row < 2 Then Exit Sub ' change row number from 2 if required
If Target.Column < 1 Then Exit Sub ' change column number if required
Application.EnableEvents = False
On Error GoTo message
edate = CDate(Target.Value)
Target.Clear
Target.Value = Format(edate, "dd mmm yyyy") ' change format to suit
exitsub:
Application.EnableEvents = True
Exit Sub
message:
MsgBox "You have not entered a valid date"
Target.Clear
Target.Activate
Resume exitsub
End Sub

To use
Copy the code as above
Right click on the sheet tab where you want the validation
View Code
This will open the VB Editor
Paste the code into the white pane that appears
Alt+F11 to return to Excel


--
Regards
Roger Govier

"Kimti" wrote in message
...
How can I set a date format for any cell and user has to use that format
otherwise user is not allowed to enter any date.

__________ Information from ESET Smart Security, version of virus
signature database 4738 (20100102) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 4738 (20100102) __________

The message was checked by ESET Smart Security.

http://www.eset.com



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default date format

It works perfact for one column. Thanks, I have some more columns on same
sheet has some dates and would like to do same thing on them. I was trying to
copy your code and was changing the column, but did not work. I have columns
8, 9, and 10 with the dates in same sheet.

Your help is much appriciated.
Thanks,

"Roger Govier" wrote:

Hi

you can only do it with code.
The following is some event code which would ensure that only dates can be
entered in column A, strating from row 2.
Adjust to suit your nededs.
also, date format has been set as dd mmm yyyy e.g. 02 Jan 2010, again change
to suit the format you want.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim edate As Date
If Target.Row < 2 Then Exit Sub ' change row number from 2 if required
If Target.Column < 1 Then Exit Sub ' change column number if required
Application.EnableEvents = False
On Error GoTo message
edate = CDate(Target.Value)
Target.Clear
Target.Value = Format(edate, "dd mmm yyyy") ' change format to suit
exitsub:
Application.EnableEvents = True
Exit Sub
message:
MsgBox "You have not entered a valid date"
Target.Clear
Target.Activate
Resume exitsub
End Sub

To use
Copy the code as above
Right click on the sheet tab where you want the validation
View Code
This will open the VB Editor
Paste the code into the white pane that appears
Alt+F11 to return to Excel


--
Regards
Roger Govier

"Kimti" wrote in message
...
How can I set a date format for any cell and user has to use that format
otherwise user is not allowed to enter any date.

__________ Information from ESET Smart Security, version of virus
signature database 4738 (20100102) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 4738 (20100102) __________

The message was checked by ESET Smart Security.

http://www.eset.com



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default date format

Also when I delete the date, it gave me some date in 1900. If I delete the
date I would like to see the cell blank.

"Kimti" wrote:

It works perfact for one column. Thanks, I have some more columns on same
sheet has some dates and would like to do same thing on them. I was trying to
copy your code and was changing the column, but did not work. I have columns
8, 9, and 10 with the dates in same sheet.

Your help is much appriciated.
Thanks,

"Roger Govier" wrote:

Hi

you can only do it with code.
The following is some event code which would ensure that only dates can be
entered in column A, strating from row 2.
Adjust to suit your nededs.
also, date format has been set as dd mmm yyyy e.g. 02 Jan 2010, again change
to suit the format you want.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim edate As Date
If Target.Row < 2 Then Exit Sub ' change row number from 2 if required
If Target.Column < 1 Then Exit Sub ' change column number if required
Application.EnableEvents = False
On Error GoTo message
edate = CDate(Target.Value)
Target.Clear
Target.Value = Format(edate, "dd mmm yyyy") ' change format to suit
exitsub:
Application.EnableEvents = True
Exit Sub
message:
MsgBox "You have not entered a valid date"
Target.Clear
Target.Activate
Resume exitsub
End Sub

To use
Copy the code as above
Right click on the sheet tab where you want the validation
View Code
This will open the VB Editor
Paste the code into the white pane that appears
Alt+F11 to return to Excel


--
Regards
Roger Govier

"Kimti" wrote in message
...
How can I set a date format for any cell and user has to use that format
otherwise user is not allowed to enter any date.

__________ Information from ESET Smart Security, version of virus
signature database 4738 (20100102) __________

The message was checked by ESET Smart Security.

http://www.eset.com




__________ Information from ESET Smart Security, version of virus signature database 4738 (20100102) __________

The message was checked by ESET Smart Security.

http://www.eset.com



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
change date format dd/mm/yyyy to Julian date format? itzy bitzy Excel Worksheet Functions 1 December 8th 09 07:42 PM
convert serial date format to normal date format Flagworld Excel Discussion (Misc queries) 3 September 23rd 08 01:32 PM
Convert date + time text format to date format Paul Ho Excel Worksheet Functions 2 May 22nd 07 05:47 PM
Excel 2000 date format cannot be set to Australian date format Brian Jones Excel Discussion (Misc queries) 1 March 30th 05 06:03 AM


All times are GMT +1. The time now is 10:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"