Is ActiveCell > or < today?

RWayneH
RWayneH used Ask the Experts™
on
Must be doing something wrg.  Every date I give it is less than today.  Using yyyy-mm-dd format, tried formatting data as ShortDate, General, and others... still can not get this to recognize a date as in the future?  It does not give me a positive number for 9999-12-31?  Any ideas?  Please advise and thanks.

 TargetDate  = ActiveCell.Value 'format?
            Diff = DateDiff("d", Now, TargetDate)
            If Diff < 0 Then
                MsgBox ("Date is in the past, less than today" & Diff)
            ElseIf Diff > 0 Then
                MsgBox ("Date is in the future, greater than today" & Diff)
            End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Martin Liss"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Are your target cells formatted as date?

Author

Commented:
I tried that formatted as ShortDate

Author

Commented:
Tried it again and it worked.  arg.
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This works for me.
29168112.xlsm

Author

Commented:
Yup, had to use: Selection.NumberFormat = "m/d/yyyy"
Martin Liss"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Is there anything else I can do for you here?

Author

Commented:
Thanks
Martin Liss"Life would be infinitely happier if we could only be born at the age of eighty and gradually approach eighteen." - Mark Twain
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You're welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial