Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Comparing date values


Nick,

Thanks for the help.

Ken

"NickH" wrote:

Hi Ken


It looks like your test is the wrong way around. Try If strEndDate <
strStartDate then ..

A simpler way to achieve the same result is:

Private Sub sValidateDate(Target As Range, Optional EndDate As Boolean)
If Not IsDate(Target) Then Exit Sub
If EndDate Then
If (Target.Offset(-1, 0) - Target) = 90 Then Exit Sub
MsgBox "Date must be at least 90 days greater than start date.",
vbOKOnly + vbExclamation, "Invalid Date Entry"
Else
If Target = Date Then Exit Sub
MsgBox "Date must be greater than current date.", vbOKOnly +
vbExclamation, "Invalid Date Entry"
End If
Target = ""
Target.Activate
End Sub

--
Nick


"Ken Warthen" wrote:

I'm using the following code to compare to date values. The values are from
two cells (start date, end date) on a spreadsheet. I need to insure the end
date is 90 days greater than the start date. The cells are formatted as
dates. A subroutine (sValidateDate) is called from code triggered in the
Worksheet_Change event.

When I step through the code with an end date less than 90 days greater than
the start date, the code within the IF strEndDate strStartDate statement
does not trigger. Any idea on what I'm doing wrong here?

Ken Warthen


Private Sub sValidateDate(Target As Range, Optional EndDate As Boolean)
Dim strStartDate
Dim strEndDate


If Target < "" Then
Select Case EndDate
Case False 'Target is a start date
If CVDate(Target.Value) < Date Then
MsgBox "Date must be greater than current date.",
vbOKOnly + vbExclamation, "Invalid Date Entry"
Cells(Target.Row, Target.Column) = ""
Cells(Target.Row, Target.Column).Activate
End If
Case True 'Target is an end date
strStartDate = Cells(Target.Row - 1, Target.Column).Value
strEndDate = Target.Value
strStartDate = strStartDate + 90
If strEndDate strStartDate Then
MsgBox "Date must be at least 90 days greater than start
date.", vbOKOnly + vbExclamation, "Invalid Date Entry"
Cells(Target.Row, Target.Column) = ""
Cells(Target.Row, Target.Column).Activate
End If
Case Else
End Select
End If

End Sub


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
If Then statement comparing date values ll Excel Programming 1 September 13th 07 05:32 PM
Help with Comparing values and retrieving values in Excel!!!!!! [email protected] Excel Worksheet Functions 1 November 17th 06 12:21 AM
Comparing values between columns only when there are values in bot Mark K Excel Worksheet Functions 1 February 19th 06 06:47 PM
Comparing values in two columns and displaying missing values in n cpetta Excel Programming 1 April 2nd 05 06:18 AM
Macro for comparing 2 values (number and date) marthab Excel Programming 2 August 19th 04 10:21 PM


All times are GMT +1. The time now is 10:23 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"