Consulting

Results 1 to 3 of 3

Thread: date comparison on two ranges

  1. #1

    date comparison on two ranges

    '... if the cells are not empty then change the number format
    					    '... to the date format DD MMM YY
    					    If Range(sRange).Text <> "" Then
    						    Range(sRange).NumberFormat = "dd mmm yy"
    					    End If
    					    If Range(sTempRange).Text <> "" Then
    						    Range(sTempRange).NumberFormat = "dd mmm yy"
    					    End If
    Is there a way to check if the text/value inside sTempRange is not earlier than the text/value inside sRange??

    For e.g. I have a problem in my sheet as sRange = 29-Dec-05 and sTempRange = 31-Mar-05.

    Can i do a check or something for this?

    Thanks.

    Picco

  2. #2
    Dim dateFirst As System.DateTime
     	Dim dateSecond As System.DateTime
     	dateFirst = txtFirstDate.Text.Trim()
     	dateSecond = args.Value
     	If dateSecond < dateFirst Then
     	  args.IsValid = False
     	  valSecondDate.ErrorMessage = "Second Date must be equal to or later than First Date!"
     	  Exit Sub
     	End If
    I found this code for what i think is VB.NET?

    Can this be used

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not tested

    [vba]
    Dim dateFirst As System.DateTime
    Dim dateSecond As Date
    dateFirst = CDate(Range(sRange).Text)
    dateSecond = CDate(Range(sTempRange).Text)
    If dateSecond < dateFirst Then
    MsgBox "Second Date must be equal to or later than First Date!"
    Exit Sub
    End If

    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •