×

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

VBA WeekdayName Function

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

VBA WeekdayName Function

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

VBA WeekdayName Function

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

VBA WeekdayName Function

Related Topics

Excel VBA Space Function

VBA Space Function: The Space function in VBA creates a String consisting of a specified number of spaces. Syntax Space (Number) Parameter Number (required) - This parameter represents the number of spaces. Return This function returns a...

1 minute read.

Excel VBA Second Function

Excel VBA Second Function: The Second function in VBA returns the second element for the specified time.  Syntax Second (Time) Parameter Time (required) – This parameter represents the time. Return This function returns the second...

1 minute read.

How to save Macro Workbook?

Saving Macro Workbook Default Excel File Extension The default excel file extension is “.xlsx”. But the standard file extension “.xlsx” cannot contains macros. So, the workbook contains macro when save din.xlsx file, all VBA...

1 minute read.

Looping in VBA

Looping in VBA There are many situations where a programmer needs to execute a block of the repetitive code number of times. Writing the same statement will make the program tedious and monotonous....

3 minutes read.

Excel VBA UCase Function

The UCase function in VBA converts a String into upper case text. Syntax UCase (String) Parameter String (required) – This parameter represents the string that you want to convert to upper case. Return This function returns a string...

1 minute read.

Excel VBA StrConv Function

The StrConv function in VBA converts a string into a specified format. Syntax StrConv (String, Conversion, [LocaleID]) Parameter String (required) – This parameter represents the string to be converted. Conversion (required) – This parameter specifies the type of conversion. It can...

1 minute read.

Excel VBA IsNumeric Function

VBA IsNumeric Function: The IsNumeric function in VBA returns a Boolean value showing whether the specified Expression contains a numeric value or not. Syntax IsNumeric (Expression) Parameter Expression (required)- This parameter represents the variant that...

1 minute read.

VBA UBound

VBA UBound  The UBound or Upper Bound function in VBA is used to specify the length of an array and returns the highest subscript for a dimension for the specified array. It is...

3 minutes read.

VBA Find Function

VBA Find Function The Excel VBA FIND function finds any information in your Excel. It can be used on a Range object on the worksheet. It works the same, unlike the Excel Find &...

6 minutes read.

If ElseIf ElseIf Statement or Nested If statement in VBA

VBA Excel: If … ElseIf … ElseIf Statement or Nested If statement This function enables you to check multiple conditions and, based on that, then run one of the statement blocks present. If...

2 minutes read.

VBA Subscript out of Range

What is Subscript out of Range? The VBA Subscript out of Range error (which is also called as Run-Time Error 9) mostly triggers when the user selects any cell, sheet, or workbook which does...

5 minutes read.

Miscellaneous Exercise of conditional statements and Loop

We have the already worked with syntax and examples of conditional statements and loops in the previous tutorials. In this tutorial, we will learn how to work with both together.  We will explain...

3 minutes read.

VBA Regex

What is a Regex? Regex stands for Regular Expression is basically a pattern matching strings within another string. They are supported in many languages, including .net, C++, Python, etc. They are...

5 minutes read.

Excel VBA : With End-with Constructs

With End-with Constructs The With-End With construct enables the user to perform multiple operations on a single object. If you are going to perform several different actions on the same object and typing the same...

4 minutes read.

Excel VBA CBool Function

VBA CBool Function: The CBool function in VBA calculates an expression and returns the result as a Boolean data type. Syntax CBool (Expression) Parameter Expression (required) – This parameter represents the expression that that you want...

1 minute read.

Excel VBA IsObject Function

VBA IsObject Function: The IsObject function in VBA returns a Boolean value showing whether the specified variable represents an Object variable type or not. Syntax IsObject (Expression) Parameter Expression (required)- This parameter represents the...

1 minute read.

Excel VBA IsArray Function

VBA IsArray Function: The IsArray function in VBA returns a Boolean, showing whether the given variable is an Array or not. Syntax IsArray (VarName) Parameter VarName (required)- This parameter represents the variable that you want...

1 minute read.

UserForm and its Properties Excel VBA

UserForm and its Properties Userform has certain properties that can be viewed as category wise (based on appearance, behavior, font) or in an alphabetic manner. The property window is used to set or...

11 minutes read.

Excel VBA InStr Function

VBA InStr Function The InStr function in VBA searches for a substring inside the given string. It returns the position of a substring within a string, as an integer if the substring is found...

1 minute read.

Excel VBA IsMissing Function

VBA IsMissing Function: The IsMissing function in VBA checks if any parameter to a procedure is missing or not. It returns a Boolean value True if the specified parameter has not been...

1 minute read.