#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default is date?

Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate
function in vba. however that does not do it if i write an invalid date
usijng the correct date format eg 2007-04-33. is there any way to check to
see if a date is ok or not? i would really appreciate help regarding this
matter. thanks alot!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default is date?

Sub arne()
Dim s As String
Dim d As Date
s = Application.InputBox("enter date", 2)
MsgBox (s)
d = DateValue(s)
MsgBox (d)
End Sub


gets the date as a pure string, can accept many formats. Accepts 2007-4-21
will raise an error on 2007-4-33.

Just add on error code to handle it the way you want.
--
Gary''s Student - gsnu200729


"Arne Hegefors" wrote:

Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate
function in vba. however that does not do it if i write an invalid date
usijng the correct date format eg 2007-04-33. is there any way to check to
see if a date is ok or not? i would really appreciate help regarding this
matter. thanks alot!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default is date?

Arne,
In the immediate window:
?isdate("2007-04-33")
False

You mean this returns true for you ?

NickHK

"Arne Hegefors" wrote in message
...
Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate
function in vba. however that does not do it if i write an invalid date
usijng the correct date format eg 2007-04-33. is there any way to check to
see if a date is ok or not? i would really appreciate help regarding this
matter. thanks alot!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default is date?

Hi Nick! Yes to me it seems like isDate only gives false when the actual
format is no good. when the date is nonsens but format is godd eg 2007-04-35
vba reads it like 00:00:00. si it fixed it lik this:

If IsDate(datStartdate) = True Then
If datStartdate = "00:00:00" Then
MsgBox "Invalid start date. Please enter valid start date.",
vbOKOnly, "Error message"
Exit Sub
End If
End If





"NickHK" skrev:

Arne,
In the immediate window:
?isdate("2007-04-33")
False

You mean this returns true for you ?

NickHK

"Arne Hegefors" wrote in message
...
Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate
function in vba. however that does not do it if i write an invalid date
usijng the correct date format eg 2007-04-33. is there any way to check to
see if a date is ok or not? i would really appreciate help regarding this
matter. thanks alot!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default is date?

Maybe you can check the year to see if it's valid for your data:

Dim datStartDate As Date
datStartDate = Application.InputBox(Prompt:="Enter a date", Type:=1)
If Year(datStartDate) < 2005 _
Or Year(datStartDate) 2010 Then
MsgBox "Please enter a valid date"
Else
MsgBox Format(datStartDate, "mmmm dd, yyyy")
End If

Application.inputbox with type:=1 won't let the user enter 2007-04-35.



Arne Hegefors wrote:

Hi Nick! Yes to me it seems like isDate only gives false when the actual
format is no good. when the date is nonsens but format is godd eg 2007-04-35
vba reads it like 00:00:00. si it fixed it lik this:

If IsDate(datStartdate) = True Then
If datStartdate = "00:00:00" Then
MsgBox "Invalid start date. Please enter valid start date.",
vbOKOnly, "Error message"
Exit Sub
End If
End If

"NickHK" skrev:

Arne,
In the immediate window:
?isdate("2007-04-33")
False

You mean this returns true for you ?

NickHK

"Arne Hegefors" wrote in message
...
Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate
function in vba. however that does not do it if i write an invalid date
usijng the correct date format eg 2007-04-33. is there any way to check to
see if a date is ok or not? i would really appreciate help regarding this
matter. thanks alot!





--

Dave Peterson


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
Concatenate including a date so that the date appears as a date Zembu Excel Worksheet Functions 2 January 6th 10 06:09 PM
date in Cell to change colors if the date is beyond today's date Pete Elbert Excel Discussion (Misc queries) 2 June 6th 09 06:31 AM
Report Date - Date Recv = Days Late, but how to rid completed date MS Questionnairess Excel Worksheet Functions 1 January 24th 07 11:05 PM
copy date based on date -refer to date range mindpeace[_4_] Excel Programming 1 June 3rd 06 01:30 PM
Date updates from worksheet to chart & changes date to a date series! Help!! Jayjg Charts and Charting in Excel 2 January 22nd 05 03:00 PM


All times are GMT +1. The time now is 04:08 PM.

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

About Us

"It's about Microsoft Excel"