PDA

View Full Version : Solved: Check if today is a specific date that falls on certain weekday regardless of year



ksohn
05-08-2012, 10:22 PM
Hi,

I was wondering if I could find some answer that I can adapt, but seems like there are none so here I go,
my first post!

I need a code that checks if today is January 1st - regardless of which year, because I want this code to work every year - and if it falls on either Friday or Saturday.
If today's date satisfies both conditions, then I want a msgbox to pop up and say "YES". If not, then "NO"

This is what I have for now:

If Weekday(NewYearsDay) = vbFriday Or Weekday(NewYearsDay) = vbSaturday Then
MsgBox "YES"
Else
MsgBox "NO"
End If

But where I struggle is the part where I actually declare what "NewYearsDay" is.. :(
Or maybe I need to approach it in an entirely different way.


Any help is appreciated!

GTO
05-09-2012, 12:23 AM
Greetings and welcome to vbaexpress!

Not tested, but I think this should do what you want.

Option Explicit


Sub example()
MsgBox NewYearsDaySpecial()
End Sub

Function NewYearsDaySpecial() As Boolean
If Date = DateSerial(Year(Date), 1, 1) And Weekday(Date, vbSunday) >= 6 Then
NewYearsDaySpecial = True
End If
End Function


Hope that helps, and again, welcome to VBAX:hi: ,

Mark

ksohn
05-09-2012, 01:13 AM
I tested with today's date and weekday, and it worked like a charm!
You're amazing, thanks a lot!


Karen

Bob Phillips
05-09-2012, 01:25 AM
Just for fun

Function NewYearsDaySpecial() As Boolean
NewYearsDaySpecial = Date = [EOMONTH(TODAY(),-MONTH(TODAY()))+1] And Weekday(Date, vbSunday) >= 6
End Function