What is VBA WEEKDAYNAME Function
The VBA WEEKDAYNAME function is listed under the date category of VBA functions. When you use it in a VBA code, it returns the day’s (weekdays) name by using the integer supplied as the day number. In simple words, it returns the day name using the a day’s number of the week (ranging 1 to 7).
how to use it
To use VBA's WEEKDAYNAME function you need to understand its syntax and arguments:
WeekdayName(Weekday, [Abbreviate], [FirstDayOfWeek])
- Weekday: An integer to specify the day ranging from 1 to 7.
- [Abbreviate]: A boolean value to specify if you need a full name of the month or abbreviated name [This is an optional argument and if omitted VBA takes FALSE by default].
- Use TRUE for abbreviated name (i.e. "Jan", "Feb", "Mar", etc.) or FALSE for full name (i.e. "January", "February", "March", etc.)
- [FirstDayOfWeek]: A string to define the first day of the week [This is an optional argument and if omitted VBA takes vbSunday by default].
- vbUseSystemDayOfWeek - As per the system settings.
- vbSunday - Sunday
- vbMonday - Monday
- vbTuesday - Tuesday
- vbWednesday - Wednesday
- vbThursday - Thursday
- vbFriday - Friday
- vbSaturday - Saturday
Example to use WEEKDAYNAME Function in VBA
To practically understand how to use VBA WEEKDAYNAME function, you need to go through the below example where we have written a vba code by using it:
Sub example_WEEKDAYNAME() Range("A1").Value = WeekdayName(1, "True", vbMonday) End Sub
In the above code, we have used WEEKDAYNAME and we have used 1 to get the first day of the week, TRUE to get the abbreviated weekday name, and vbMonday to set Monday as the first day of the week. In the result, we have Mon in cell B1.
About the Author
Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.