×

Excel VBA Weekday Function

Excel VBA Weekday Function: The TimeValue function in VBA returns an integer (1 to 7), signifying the day of the week for the specified date.

Syntax

Weekday (Date, [FirstDayOfWeek])

Parameter

Date (required) – This parameter represents a valid String interpretation of time.

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 an integer (1 to 7), signifying the day of the week for the specified date.

Example 1

Sub WeekdayFunction_Example1()
 'It will return the weekday for the given date
 Dim wekday_val As Integer
 wekday_val = weekday(#2/11/2020#)
 ' The variable wekday_val now equals 03.
 Cells(1, 1).Value = wekday_val
 End Sub 

Output

3

VBA Weekday Function

Example 2

Sub WeekdayFunction_Example2()
 'It will return the weekday for the given date
 Dim wekday_val As Integer
 'the week will start with Monday
 wekday_val = weekday(#2/11/2020#, vbMonday)
 ' The variable wekday_val now equals 02.
 Cells(1, 1).Value = wekday_val
 End Sub 

Output

2

VBA Weekday Function

Example 3

Sub WeekdayFunction_Example3()
 'It will return the weekday for the given date
 Dim wekday_val As Integer
 'the week will start with Thursday
 wekday_val = weekday(#12/31/2020#, vbThursday)
 ' The variable wekday_val now equals 1.
 Cells(1, 1).Value = wekday_val
 End Sub 

Output

1

VBA Weekday Function

Example 4

Sub WeekdayFunction_Example4()
 ' It will return the weekday for the date
 Dim wekday_val As String
 'will returns today's weekday
 wekday_val = WeekdayName(weekday(Now()))
 ' The variable wekday_val will return the string "Tuesday".
 Cells(1, 1).Value = wekday_val
 End Sub 

Output

Tuesday

VBA Weekday Function

Related Topics

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.

VBA VBScript Regex Methods Regex

VBA VBScript Regex Methods Regex The VBA Regex supports 3 methods which are as follows: ExecuteReplaceText Execute The execute method is used to extract a match from the given based on the defined matching...

3 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.

VBA Pivot Table

What is a Pivot Table? One of the most powerful features of Excel VBA is the Pivot Table. A pivot table is a VBA tool that is used to create summary...

3 minutes read.

VBA Updating Pivot Table

VBA- Updating Pivot Table The pivot table is an important feature to explore, summarize, and interpret the bulk amount of data. It helps data evaluating, reviewing, as well as making useful...

3 minutes read.

Excel VBA Mid Function

VBA Mid Function: The Mid function in VBA returns a substring from within a supplied string. Syntax Mid (Str, Start, [Length]) Parameter Str (required) -This parameter represents a string from which you want to extract the substring. Start...

1 minute read.

Excel VBA DateAdd Function

The DateAdd function in VBA adds a time interval to a supplied date and/or time and returns the resultant date/time. Syntax Dateadd (Interval, Number, Date) Parameter Interval (required) – This parameter a string specifying the interval to be...

1 minute read.

Excel VBA Year Function

Excel VBA Year Function: The Year function in VBA returns the four-digit year for the specified date. Syntax Year (Date) Parameter Date (required) – This parameter represents the significant date. Return This function returns the four-digit year...

1 minute read.

Userform Events

What are Events? Anything you do in to trigger an excel file is an event (an action). Example: If you want a greeting message ‘Good Day’ whenever an excel file is...

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

Declaring a Variable in VBA

Declaring a Variable A variable is broadly described as a storage location combined with a name and representing a specific value. Declaring a variable is instructing the computer to reserve space...

2 minutes read.

Excel VBA InputBox

Input Box The InputBox function in VBA is used to prompt the users to enter values. The user can click either the OK button or can choose the CANCEL button. If the user clicks...

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

Excel VBA StrReverse Function

The StrReverse function returns a String after reversing the given String. Syntax StrReverse (Expression) Parameter Expression (required) – This parameter represents the String that you want to reverse. Return This function returns a String after reversing the given String. Example...

1 minute read.

Excel VBA CDbl Function

VBA CDbl Function: The CDbl function in VBA converts an expression into a Double data type. Syntax CDbl (Expression) Parameter Expression (required) - This parameter represents the expression that that you want to convert to...

1 minute read.

Excel VBA INT Function

VBA INT Function: The INT function in VBA rounds the given supplied number down and returns an integer value. The positive numbers are rounded to zero, and the negative numbers are rounded away from zero. Syntax Int...

1 minute read.

Excel VBA Oct Function

VBA Oct Function: The Oct function in VBA converts the given number into octal notation and returns the result as a string. Syntax Oct (Number) Parameter Number (required) – This parameter represents the numeric value...

1 minute read.

Excel VBA Choose Function

VBA Choose Function: The Choose function in VBA chooses function selects the corresponding value from a list of arguments depending as per the specified index. Syntax Choose (Index, [Choice-1], [Choice-2], ...) Parameter Index (required) – This...

2 minutes read.

Excel VBA FormatPercent Function

VBA FormatPercent Function: The FormatPercent function in VBA is used to apply a percent format to a numeric expression, and it returns the result as a string. Syntax FormatPercent (Expression, [NumDigitsAfterDecimal], [IncludeLeadingDigit], [UseParensForNegativeNumbers], [GroupDigits]) Parameter Expression (required)...

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