p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Excel VBA (http://p2p.wrox.com/forumdisplay.php?f=79)
-   -   check dates against each other from differentrange (http://p2p.wrox.com/showthread.php?t=36247)

crmpicco December 19th, 2005 06:49 AM

check dates against each other from differentrange
 

Code:

'... 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

www.crmpicco.co.uk

shattered December 19th, 2005 11:26 AM

depends on how the data is stored - if its in date format then its a simple case of comparing one date to the other

With Sheets("Sheet1")
    If .Cells(2, 2).Value < .Cells(2, 3).Value Then
        .Cells(2, 4).Value = "Before"
    Else
        .Cells(2, 4).Value = "After"
    End If
End With

if its stored purely as text then its a case of parsing the text and then passing it as a date before doing the comparison




All times are GMT -4. The time now is 10:21 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.