×

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

VBA ActiveSheet

What is VBA Activesheet Property? The active sheet means the current worksheet which you are working on and viewing. The ActiveSheet object signifies the worksheet tab that is selected before running the VBA...

5 minutes read.

VBA Type Mismatch Error

What is a Type Mismatch Error? VBA Type Mismatch Error is a run time error in excel, which often occurs when the data types contained in a VBA code are not matched...

3 minutes read.

Excel VBA Sin Function

VBA Sin Function: The Sin function in VBA returns the sine value for a supplied angle. Syntax Sin (Number) Parameter Number (required) –This parameter represents the angle (in radians) to calculate the sine value. Return This function...

1 minute read.

Excel VBA LBound Function

Excel VBA LBound Function: The LBound function in VBA returns the lowest subscript for the specified dimension in the given array. Syntax LBound (ArrayName, [Dimension]) Parameter ArrayName (required) – This parameter represents an array for which...

1 minute read.

Excel VBA Fix Function

VBA Fix Function: The Fix function in VBA truncates the given number to an integer and returns the rounded off integer number. This function both positive and negative numbers to zero. Syntax Fix...

1 minute read.

Basics of Userform

A User Form is a built-in customized dialog box that fetches data from the user through a user-friendly dialog box or window that makes up part of an application's user interface. It...

9 minutes read.

Excel VBA Tutorial

What is VBA? Introduction to Excel VBA: Visual Basic for Applications (VBA) is a programming language developed by Microsoft to automate operations in applications, such as Excel, Word, PowerPoint, etc. It...

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 Error Function

VBA Error Function: The Error function in VBA returns the error message corresponding to a supplied error code. Syntax Error ([ErrorNumber]) Parameter ErrorNumber (optional) – This parameter represents the required error number. By default, the...

1 minute read.

Excel VBA User-Defined Functions

User-Defined Functions One of the advantages of VBA is that you can create your own functions using macros. These functions can be called and used as other functions in excel and use them. You can...

3 minutes read.

VBA Object Required

What is Object Required Error? VBA Object Required is a run time error which occurs when the user does not define a valid object qualifier, or the assigned object doesn’t exist in the...

6 minutes read.

Excel VBA DateDiff Function

The DateDiff function in VBA returns a Long data value representing the number of intervals between two specified dates/times where the type of interval is supplied by the user. Syntax DateDiff (Interval, Date1, Date2, [FirstDayOfWeek], [FirstWeekOfYear]) Parameter Interval (required)...

2 minutes 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.

VBA Global Variable

What is Global Variable? The Global Variables in VBA refers to the variables declared before the start of any macro. They are defined outside the functions and are used by all the functions or...

6 minutes read.

Excel VBA Date Function

VBA Date Function The Date function in VBA returns the current date. Syntax Date( ) Parameter NA Return This function returns the current date. Example 1 Sub DateFunction_Example1() ' retuning the current date in the variable currentDate Dim currentDate As...

1 minute read.

Excel VBA: DO WHILE….Loop

DO WHILE….Loop The “Do While” Loop is the same, unlike the FOR statement, just that it will keep on looping till the specified condition is true. It is used when we want to...

3 minutes read.

Excel VBA Month Function

The Mont function in VBA returns the month number for the specified date. Syntax Month (Date) Parameter Time (required) – This parameter represents the date. Return This function returns the month number for the specified date. Example 1 Sub MonthFunction_Example1() ...

1 minute read.

VBA Screen Updating

What is VBA Screen Updating property? Screen Updating is a VBA property which is used to display the output generation while running the code. If this property is enabled, we could see...

6 minutes read.

Excel VBA Minute Function

The Minute function in VBA returns the minute component for the specified time. Syntax Minute (Time) Parameter Time (required) – This parameter represents the time. Return This function returns the minute component for the specified time. Example 1 Sub MinteFunction_Example1() ...

1 minute read.

Excel VBA Filter Function

VBA Filter Function: The Filter function in VBA returns a subset for the given string array, based on specified criteria. Syntax Filter (SourceArray, Match, [Include], [Compare]) Parameter SourceArray (required) – This parameter the array of Strings that you...

2 minutes read.