Excel VBA WeekdayName Function
Excel VBA WeekdayName Function: The WeekdayName function in VBA returns a string containing the weekday name, for the specified integer representation of a weekday.
Syntax
WeekdayName (Weekday, [Abbreviate], [FirstDayOfWeek])
Parameter
Weekday (required) – This parameter represents an integer between 1 and 7, representing the day of the week wherein the weekday that is represented by each integer value depends on the value of the [FirstDayOfWeek] parameter.
Abbreviate (optional) – This function represents a Boolean argument specifying whether the returned month name should be abbreviated or not. By default, it is set to False.
It can hold the following values:
True – It returns the abbreviated week name, i.e. "Sun", "Mon", etc.
False (default value) – It returns the full week name i.e. "Sunday", "Monday", etc.
FirstDayOfWeek (optional) – This parameter specifies the weekday that should be used as the first day of the week. The default value is set to vbUseSystemDayOfWeek.
It can take the following values:
- vbUseSystemDayOfWeek - The first day of the week is as specified in your system settings
- vbSunday – Sunday
- vbMonday – Monday
- vbTuesday – Tuesday
- vbWednesday – Wednesday
- vbThursday – Thursday
- vbFriday – Friday
- vbSaturday – Saturday
Return
This function returns a string containing the weekday name for the specified integer representation of a weekday.
Example 1
Sub WeekdayNameFunction_Example1() ' It will return the weekday name for the given weekday number Dim weekday As String weekday = WeekdayName(2) ' The variable weekday will return the string "Monday". Cells(1, 1).Value = weekday End Sub
Output
Monday
Example 2
Sub WeekdayNameFunction_Example2() ' It will return the weekday name for the given weekday number Dim weekday As String 'setting the abbreviated value true weekday = WeekdayName(2, True) ' The variable weekday will return the abbreviated string "Mon". Cells(1, 1).Value = weekday End Sub
Output
Mon
Example 3
Sub WeekdayNameFunction_Example3() ' It will return the weekday name for the given weekday number Dim weekday As String 'setting the abbreviated value true 'the week will start from Monday weekday = WeekdayName(2, True, vbMonday) ' The variable weekday will return the abbreviated string "Tue". Cells(1, 1).Value = weekday End Sub
Output
Tue
Example 4
Sub WeekdayNameFunction_Example4() ' It will return the weekday name for the given weekday number Dim wekday As String 'will returns today's weekname wekday = WeekdayName(weekday(Now())) ' The variable weekday will return the string "Tuesday". Cells(1, 1).Value = wekday End Sub
Output
Tuesday