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

I have a cell where people type in a date. The format is "mm/dd/yyyy" (e.g.
11/18/2005). I want to write a "If" statement to check whether the user
types in a date in that cell. If they leave it blank or type anything else,
I want to have a message box comes up. So this is what I have, and it's not
working.

If ActiveSheet.Range("B8").NumberFormat < "m/d/yyyy" Then
MsgBox "Please enter a date in cell B8.", , "Warning!"

Please help. Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default date format

How about

With Activesheet.Range("B8")
If .Value < "" Then
If Not IsDate(.Value) Then
MsgBox "Please enter a date in cell B8.", , "Warning!"
EndIf
Else
MsgBox "Please enter a date in cell B8.", , "Warning!"
End If
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"AccessHelp" wrote in message
...
I have a cell where people type in a date. The format is "mm/dd/yyyy"

(e.g.
11/18/2005). I want to write a "If" statement to check whether the user
types in a date in that cell. If they leave it blank or type anything

else,
I want to have a message box comes up. So this is what I have, and it's

not
working.

If ActiveSheet.Range("B8").NumberFormat < "m/d/yyyy" Then
MsgBox "Please enter a date in cell B8.", , "Warning!"

Please help. Thanks.



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

Thanks Bob. Your code works, but that code would not go along with mine.
That code is just a small piece of mine.

I have to use "If" statements. Basically, my whole code would test that
cell first for date. Then if it is true, it will go on to another "If"
statement and so on.

Can you help me with "IF"? Thanks.

"Bob Phillips" wrote:

How about

With Activesheet.Range("B8")
If .Value < "" Then
If Not IsDate(.Value) Then
MsgBox "Please enter a date in cell B8.", , "Warning!"
EndIf
Else
MsgBox "Please enter a date in cell B8.", , "Warning!"
End If
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"AccessHelp" wrote in message
...
I have a cell where people type in a date. The format is "mm/dd/yyyy"

(e.g.
11/18/2005). I want to write a "If" statement to check whether the user
types in a date in that cell. If they leave it blank or type anything

else,
I want to have a message box comes up. So this is what I have, and it's

not
working.

If ActiveSheet.Range("B8").NumberFormat < "m/d/yyyy" Then
MsgBox "Please enter a date in cell B8.", , "Warning!"

Please help. Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default date format

Perhaps just try

If IsDate(Range("B8").Value Then
' your code

--

HTH

RP
(remove nothere from the email address if mailing direct)


"AccessHelp" wrote in message
...
Thanks Bob. Your code works, but that code would not go along with mine.
That code is just a small piece of mine.

I have to use "If" statements. Basically, my whole code would test that
cell first for date. Then if it is true, it will go on to another "If"
statement and so on.

Can you help me with "IF"? Thanks.

"Bob Phillips" wrote:

How about

With Activesheet.Range("B8")
If .Value < "" Then
If Not IsDate(.Value) Then
MsgBox "Please enter a date in cell B8.", , "Warning!"
EndIf
Else
MsgBox "Please enter a date in cell B8.", , "Warning!"
End If
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"AccessHelp" wrote in message
...
I have a cell where people type in a date. The format is "mm/dd/yyyy"

(e.g.
11/18/2005). I want to write a "If" statement to check whether the

user
types in a date in that cell. If they leave it blank or type anything

else,
I want to have a message box comes up. So this is what I have, and

it's
not
working.

If ActiveSheet.Range("B8").NumberFormat < "m/d/yyyy" Then
MsgBox "Please enter a date in cell B8.", , "Warning!"

Please help. Thanks.






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
How do I convert dd/mm/yy date format to yyddd Julian date format itzy bitzy[_2_] Excel Worksheet Functions 8 December 11th 09 03:20 AM
change date format dd/mm/yyyy to Julian date format? itzy bitzy Excel Worksheet Functions 1 December 8th 09 07:42 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Change a date in text format xx.xx.20xx to a recognised date format concatenator Excel Programming 1 November 24th 03 11:33 PM


All times are GMT +1. The time now is 05:19 AM.

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"