MS Excel: How to use the WEEKDAYNAME Function (VBA)
This Excel tutorial explains how to use the Excel WEEKDAYNAME function with syntax and examples.
Description
The Microsoft Excel WEEKDAYNAME function returns a string representing the day of the week given a number from 1 to 7.
The WEEKDAYNAME function is a built-in function in Excel that is categorized as a Date/Time Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.
Syntax
The syntax for the WEEKDAYNAME function in Microsoft Excel is:
WeekdayName( number, [abbreviate], [firstdayofweek] )
Parameters or Arguments
- number
- A value from 1 to 7, representing a day of the week.
- abbreviate
- Optional. This parameter accepts a boolean value, either TRUE or FALSE. If this parameter is set to TRUE, it means that the weekday name is abbreviated. If this parameter is set to FALSE, the weekday name is not abbreviated.
- firstdayofweek
Optional. It determines what day is to be the first day of the week. If this parameter is omitted, it assumes that the first day of the week is Sunday. It can be any of the following values:
Constant Value Explanation vbUseSystem 0 Use the NLS API settings vbSunday 1 Sunday (default used) vbMonday 2 Monday vbTuesday 3 Tuesday vbWednesday 4 Wednesday vbThursday 5 Thursday vbFriday 6 Friday vbSaturday 7 Saturday
Returns
The WEEKDAYNAME function returns a string value.
Note
- If you use the WEEKDAYNAME function in a query, you'll have to use the numeric value (ie: 0 to 7) for the firstdayofweek parameter. You can only use the constant equivalent (ie: vbSunday to vbSaturday) in VBA code.
Applies To
- Excel for Office 365, Excel 2019, Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Function
- VBA function (VBA)
Example (as VBA Function)
The WEEKDAYNAME function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel WEEKDAYNAME function examples and explore how to use the WEEKDAYNAME function in Excel VBA code:
WeekdayName(3) Result: 'Tuesday' WeekdayName(3, TRUE) Result: 'Tue' WeekdayName(3, TRUE, vbMonday) Result: 'Wed' WeekdayName(3, TRUE, 2) Result: 'Wed'
For example:
Dim LValue As String LValue = WeekdayName(3, TRUE, vbMonday)
In this example, the variable called LValue would now contain the value of 'Wed'.
Advertisements