Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2005, 03:33 PM
Authorized User
 
Join Date: Nov 2005
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to tonyrosen
Default New Problem

Which I don't think is anything other than I'm not versed in this stuff well enough ...

Let's say you have two dates (StartDate and StopDate)

'====================================
StartDate = Range("A3") 'assuming it's already a date
StopDate = Range("A4") 'assuming it's already a date
StopYear = Year(StartDate) + 1
AfterThisDate = "12/31/" & StopYear
'====================================

I need to check to see if the StopDate is less than the AfterThisDate ...

Basically:
If StopDate < AfterThisDate Then
     'Throw an error
End If

However, it's not calculating unless the dates are equal ... Am I missing something?

 
Old November 17th, 2005, 03:54 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Tony,

I just bundled this togther for you...

startdate = Range("A3")
stopdate = Range("A4")
stopyear = CDate(("31 December " & Year(startdate) + 1))
If IsDate(startdate) And IsDate(stopdate) And IsDate(stopyear) Then
    If stopdate > stopyear Then
        MsgBox ("Stopped")
    Else
        MsgBox ("OK")
    End If
Else
End If

cheers

Matt

 
Old November 17th, 2005, 09:59 AM
Authorized User
 
Join Date: Nov 2005
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to tonyrosen
Default

I had declared the variables as String ... once I changed them to Date, it worked great.

Thanks!










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