VBA Day of the week

preview_player
Показать описание
Use a macro to identify the day of the week based on a date of your choice.

Code:
Sub day_of_the_week()

Dim myDate As Date
Dim myDate_weekday As Long
Dim myWeekday As String

'set date
myDate = Date

'find weekday number
myDate_weekday = Weekday(myDate, vbMonday)

'associate weekday number with the worded weekday
If myDate_weekday = 1 Then
myWeekday = "Monday"
ElseIf myDate_weekday = 2 Then
myWeekday = "Tuesday"
ElseIf myDate_weekday = 3 Then
myWeekday = "Wednesday"
ElseIf myDate_weekday = 4 Then
myWeekday = "Thursday"
ElseIf myDate_weekday = 5 Then
myWeekday = "Friday"
ElseIf myDate_weekday = 6 Then
myWeekday = "Saturday"
ElseIf myDate_weekday = 7 Then
myWeekday = "Sunday"
End If

'message
MsgBox ("It is a " & myWeekday)

End Sub

-------------------------------
NEED HELP?
-------------------------------
Leave a comment with your questions, issues or projetcs and I will try to answer with a video.

-------------------------------
THANK YOU
-------------------------------
For watching my videos,
Your shares
And your comments!
Рекомендации по теме