MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 13th, 2002, 04:06 PM   #1
Fun_Geek
New Member
 
Join Date: Apr 2002
Posts: 7
Default

The User will enter a 8 digit date into a cell WITHOUT "/" separators, i.e., 01152002, representing January 15, 2002.

I would like the date displayed the same (01152002). It should not require the user to lead entry with apost (').

Also, another requirement is to validate date code on entry. It must be a valid calendar date (not something like January 34, 2002).

TIA

Mike
Fun_Geek is offline   Reply With Quote
Old Apr 13th, 2002, 04:21 PM   #2
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

okay, for the format set a custom format as follows (right click the cell and choose Format Cells, then on the number tab select custom and enter the following formula):

ddmmyyyy

secondly, for the validation, select the cells and choose Validation from the Data menu, and set date and put in a lowest possible and highest possible date that the use could enter, eg. 01/01/90 and 01/01/20.
daleyman is offline   Reply With Quote
Old Apr 13th, 2002, 04:50 PM   #3
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Quote:
On 2002-04-13 15:06, Fun_Geek wrote:
The User will enter a 8 digit date into a cell WITHOUT "/" separators, i.e., 01152002, representing January 15, 2002.

I would like the date displayed the same (01152002). It should not require the user to lead entry with apost (').

Also, another requirement is to validate date code on entry. It must be a valid calendar date (not something like January 34, 2002).

TIA

Mike
Hi Fun_Greek and daleyman:
daleyman's method did not work for me -- this is what did work for me
if you have the text value 1152002, 01152002 in cell A1, then in cell A2 put

=TEXT(A1,"00-00-0000")+0

This will convert your 7-digit or 8-digit text entry to a valid date simulating the day, the month, and the year in the text string.
HTH!


_________________
Yogi Anand
Edit: Deleted inactive web site reference from hard code signature line

[ This Message was edited by: Yogi Anand on 2003-01-19 17:39 ]
Yogi Anand is offline   Reply With Quote
Old Apr 13th, 2002, 07:41 PM   #4
Fun_Geek
New Member
 
Join Date: Apr 2002
Posts: 7
Default

Daleyman,

You said, "okay, for the format set a custom format as follows (right click the cell and choose Format Cells, then on the number tab select custom and enter the following formula): ddmmyyyy"

This doesn't work because:

(1) The user will enter in the format MMDDYYYY (even formatting as mmddyyyy) didn't work.

(2) Entering 01152002 in your above example will display "01265054" in the cell and "01/26/5054" in the formula bar.

You also said, "secondly, for the validation, select the cells and choose Validation from the Data menu, and set date and put in a lowest possible and highest possible date that the use could enter, eg. 01/01/90 and 01/01/20."

This will not work since the user will not be entering the "/". Again in the orignial post, I indicated that the user will enter directly to the cell "01152002" - no special characters for formatting.

Mike


Fun_Geek is offline   Reply With Quote
Old Apr 13th, 2002, 09:04 PM   #5
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

okay, try this then, pasting it into the module relating to the worksheet you are on.


Dim daypart As Integer, monthpart As Integer, yearpart As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
If IsDate(Target.Value) Then Exit Sub
If Len(Target.Value) < 7 Then Exit Sub
strg = Target.Value
If Len(strg) = 7 Then strg = "0" & strg

'validation

valid = True
If Len(strg) <> 8 Then valid = False
If IsNumeric(strg) = False Then valid = False
If valid = True Then
daypart = Abs(Left(strg, 2))
monthpart = Abs(Mid(strg, 3, 2))
yearpart = Abs(Right(strg, 4))
If daypart < 1 Or daypart > 31 Then valid = False
If monthpart < 1 Or monthpart > 12 Then valid = False
If yearpart < 1900 Or yearpart > 2050 Then valid = False
End If

'result
If valid = True Then
Target.NumberFormat = "DDMMYYYY"
Target.Value = DateSerial(yearpart, monthpart, daypart)
Else
Target.Value = "ERROR"
End If
End Sub


...only problem is it does it for the whole sheet, if you want it to cover only one column, for example column B, insert after the first line of code...

If Target.Column <> 2 Then Exit Sub

...good luck this time!

__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 13th, 2002, 09:19 PM   #6
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
Assumes numbers are entered into column A
I may be the King of overkill, but it works..
Edit to suit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
If Len(Target) = 0 Then Exit Sub
Application.EnableEvents = False
If Len(Target) = 7 Then Target = "'0" & Target
If Not IsDate(Strings.Left(Target, 2) & "/" & _
Strings.Mid(Target, 3, 2) & "/" & Strings.Right(Target, 4)) Then
MsgBox "Invalid Date Entered"
Target.Select
Application.EnableEvents = True
Exit Sub
End If
Cells(Target.Row, Target.Column + 1).Value = _
Format(Strings.Left(Target, 2) & "/" & _
Strings.Mid(Target, 3, 2) & "/" & Strings.Right(Target, 4), _
"DDDD, MMMM DD, YYYY")
End If
Application.EnableEvents = True
End Sub

Tom

[ This Message was edited by: TsTom on 2002-04-13 20:20 ]
Tom Schreiner is offline   Reply With Quote
Old Apr 13th, 2002, 09:22 PM   #7
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

well it's less lines of code than mine, does that make me the Emperor of Overkill?
__________________

<table style="background-color:#0e54be" cellspacing="1" cellpadding="2"><td style="background-color:#ceffff;font-family:arial;color:#072c63;font-size:8pt;">***DALEY** :P**</td></table>
daleyman is offline   Reply With Quote
Old Apr 13th, 2002, 09:30 PM   #8
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Sorry Daley,
I would not have even posted it if I would have seen your post...
Had to sign off right in the middle of writing it.
Tom
Tom Schreiner is offline   Reply With Quote
Old Apr 13th, 2002, 09:36 PM   #9
daleyman
Board Regular
 
Join Date: Mar 2002
Location: London, UK
Posts: 167
Default

not at all, is always interesting to see different ways of skinning the same cat.
daleyman is offline   Reply With Quote
Old Apr 14th, 2002, 12:39 AM   #10
Fun_Geek
New Member
 
Join Date: Apr 2002
Posts: 7
Default

How would I proceed with the code? Assume pasting it somewhere into the VBE...
Fun_Geek is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 01:00 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes