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 May 2nd, 2002, 09:25 AM   #1
paulyf
New Member
 
Join Date: Mar 2002
Location: Paul
Posts: 34
Default

Hi all,

I've got three text boxes on a form, entitled "day", "month" and "year". I've managed to concactenate them and format them into a date that I can plug into Excel. However, there is nothing to stop the user selecting an invalid date, e.g. 31st April 2001.

Does anybody have example code to allow only valid dates to be entered????

Many Thanks in anticipation.

Cheers - Paul
paulyf is offline   Reply With Quote
Old May 2nd, 2002, 09:40 AM   #2
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

One method I've used, is to use comboboxes instead of text boxes. Combos are a pain in the arse for the user, but can be a programmer's delight.

However, to answer your question, you're going to have to create validation code yourself, but here's a format I suggest (I've assumed that your Month textbox is called txtMonth and the Day textbox is called txtDay):


Select Case txtMonth.Text

Case 1, 3, 5, 7, 8, 10, 12 '31 day months
If txtDay.Text > 31 Then
MsgBox "There aren't that many days!"
End If
Case 4, 6, 9, 11
If txtDay.Text > 30 Then '30 day months
MsgBox "There aren't that many days!"
End If
Case Else 'February
'You're going to want to check for a leap year here.

End Select


Note:: I've used numbers for the months, you can put in the words or whatever instead. (just remember if you're using text use double quotes around them)

I hope this is a good start for you.
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old May 2nd, 2002, 09:46 AM   #3
paulyf
New Member
 
Join Date: Mar 2002
Location: Paul
Posts: 34
Default

Thanks A Lot Mark - That's Great!

I've stumbled upon the IsDate function - does that have any limitations?

Cheers - Paul
paulyf is offline   Reply With Quote
Old May 2nd, 2002, 10:24 AM   #4
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Just a thought.

You could ask the user to select the month first, then the year, finally the day.

This order of selection would allow you to dynamically construct the list of the day numbers to be shown.

The formula that follows would produce such a list. Put it in a cell in the first row where the other lists are:

=IF(MONTH(DATE($B$1,$A$1,ROW()))=$A$1,DAY(DATE($B$1,$A$1,ROW())),"")

to be copied down till row 31.

A1 is where the month is selected and B1 is where the year is selected.

You need to name this range using an OFFSET formula. You can then use the name so created as source list.

Aladin

[ This Message was edited by: Aladin Akyurek on 2002-05-02 09:28 ]

[ This Message was edited by: Aladin Akyurek on 2002-05-02 09:29 ]
Aladin Akyurek is offline   Reply With Quote
Old May 2nd, 2002, 10:46 AM   #5
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Quote:
On 2002-05-02 08:46, paulyf wrote:
Thanks A Lot Mark - That's Great!

I've stumbled upon the IsDate function - does that have any limitations?

Cheers - Paul
The only limitation that's immediately obvious to me is that it wont tell you what part of the date is wrong. (since it's a boolean check) Apart from that, there's no harm in using "IsDate".
__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Feb 28th, 2004, 02:15 PM   #6
qmp
New Member
 
Join Date: Feb 2004
Posts: 26
Default Re: Date validation code

I have the same thing in my budget progam. I use the validation box.

After you set your range using setting click on the input message tab and put a message with your dropdown box, which you don't have to show. Just unclick "Show input message when cell is selected"

Then select the error alert tab and put a message here also. Like the input message you can unshow this also.

These will not let you to put anything in the cell unless its in the dropdown list.... hope this helps.......... qmp
qmp 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 04:14 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