Excel VBA - corresponding day in previous month

Hi
I would appreciate help with trying to return a TRUE/FALSE as to whether there a corresponding day in the previous month.  

For example, if the current day is 25th Feb 2019, return TRUE since there is a corresponding day (25th Jan 2019) in the previous month.  But if the current day is 31st Dec 2018 return FALSE since there is no corresponding day in the previous month.

Thanks in advance
Alison
alisonthomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
Why VBA?
alisonthomAuthor Commented:
It is part of other VBA I am writing
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try this user defined function to test if the same day exists in the previous month.

Function IsDateAvailableInPreviousMonth(dt As Date) As Boolean
    Dim ldt As Date
    On Error Resume Next
    ldt = DateValue(Year(dt) & "-" & Month(dt) - 1 & "-" & Day(dt))
    If Err = 0 Then IsDateAvailableInPreviousMonth = True
    On Error GoTo 0
End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alisonthomAuthor Commented:
Hi Subodh,  that is exactly what I was looking for.  Many thanks!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Alisonthom! Glad it worked as desired.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.