ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check date (https://www.excelbanter.com/excel-programming/427043-check-date.html)

Woodi2

Check date
 
I would like a code that checks that a date enetered is not greater than
todays date. In Cell A1 i have an autosum NOW() that displays todays date.
I have some code below that i have tried to manipulate from elswhere but its
not working.
A userform opens and i want the date in textbox 1 to be checked to ensure it
is no greater than todays date. Am i anywhere near and also can code be used
to check against an autosum value?

Do
If IsDate(Me.TextBox1.Value) Then
If Val(Me.TextBox1.Value) Range("A1") Then
MsgBox "date cannot be greater than today's date"
Me.TextBox1.SetFocus
Exit Sub
End If
Else
MsgBox ("Bad Value")
End If
Loop While Not IsDate(Me.TextBox1.Value)

joel

Check date
 
from
If Val(Me.TextBox1.Value) Range("A1") Then
to
If DateValue(Me.TextBox1.Value) Range("A1") Then

"Woodi2" wrote:

I would like a code that checks that a date enetered is not greater than
todays date. In Cell A1 i have an autosum NOW() that displays todays date.
I have some code below that i have tried to manipulate from elswhere but its
not working.
A userform opens and i want the date in textbox 1 to be checked to ensure it
is no greater than todays date. Am i anywhere near and also can code be used
to check against an autosum value?

Do
If IsDate(Me.TextBox1.Value) Then
If Val(Me.TextBox1.Value) Range("A1") Then
MsgBox "date cannot be greater than today's date"
Me.TextBox1.SetFocus
Exit Sub
End If
Else
MsgBox ("Bad Value")
End If
Loop While Not IsDate(Me.TextBox1.Value)


Woodi2

Check date
 
Thanks Joel, you have rescued my code again. Thought i was somewhere near.

"joel" wrote:

from
If Val(Me.TextBox1.Value) Range("A1") Then
to
If DateValue(Me.TextBox1.Value) Range("A1") Then

"Woodi2" wrote:

I would like a code that checks that a date enetered is not greater than
todays date. In Cell A1 i have an autosum NOW() that displays todays date.
I have some code below that i have tried to manipulate from elswhere but its
not working.
A userform opens and i want the date in textbox 1 to be checked to ensure it
is no greater than todays date. Am i anywhere near and also can code be used
to check against an autosum value?

Do
If IsDate(Me.TextBox1.Value) Then
If Val(Me.TextBox1.Value) Range("A1") Then
MsgBox "date cannot be greater than today's date"
Me.TextBox1.SetFocus
Exit Sub
End If
Else
MsgBox ("Bad Value")
End If
Loop While Not IsDate(Me.TextBox1.Value)



All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com