How do you Validate for a ValidDate in Excel97?

BillySilly

New Member
Joined
Jan 23, 2013
Messages
49
Hi
I have a worksheet that has a cell for the user to provide a StartDate. Formulae use the contents of this cell L5 to populate 60 cells on the sheet with dates and days.
This all works fine if the user enters a valid StartDate, but if the user wilfully or accidentally enters an invalid date the sheet is populated with errors.

My first thought was to use data validation in the StartDate cell, setting it to Date with 01/01/2013 as the start date and 31/12/30 as the end date. This works well if the date is invalid. It still fills the sheet with errors but gives a message box asking the user for a valid date with the Error Alert “The date must be a valid date in the form dd/mm/yy and the dd must be <=28”. Excel must therefore contain a buit-in validation routine but I don’t know what it is called or if it can be used in coding. Also you can see that any valid date will pass and I cannot see how to trap dates with Day>28 (or reduce any which are to 28) which is there to avoid roll-over problems when the Month is incremented.
Can anyone help with this?

My second thought was to write a macro called by activating the cell but I am having difficulty with using InputBox for dates as the Date functions in Excel97 don’t seem to work in a macro – I cannot assume that the user has the ToolPack installed.
Has anyone got code for InputBox for dates?
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi
I guess you are still thinking:)
If I use the first method, when the user clicks on the tick to accept the input the 'date' will be entered in L5 and if it is invalid up will pop the Message saying 'try again' and the error messages on the 60 cells will go. That is fine by me. Otherwise I could have a macro that is run after the tick event to test the Day value and decrease it to 28 if it is over 28. Could anyone suggest the code to identify the event 'L5 is selected followed by the tick and the date is accepted'?
If I use Record Macro for the tick I get
Range("L5").Select
ActiveCell.FormulaR1C1 = "1/22/2013"
while for the X I just get
Range("L5").Select
 
Last edited:
Upvote 0
So the event I want to test for to run my macro is that these two lines of code both occur

I can arrange for a valid date to be provided initially so there will not be any errors shown

So I need a macro to test for L5 changing
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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