You can use the WeekdayName function in VBA to obtain the name of the day of the week from a given date.
Here is one common way to use this function in practice:
Sub FindWeekdayName()
Dim i As Integer
For i = 2 To 9
Range("B" & i) = WeekdayName(Weekday(Range("A" & i)))
Next i
End Sub
This particular macro will find the name of the weekday for each date in the range A2:A9 and display the results in the range B2:B9.
The following example shows how to use the WeekdayName function in practice.
Note: If you would rather return the day of the week as an integer then you should use the Weekday function instead.
Example: How to Use WeekdayName Function in VBA
Suppose we have the following column of dates in Excel:
Suppose we would like to obtain the name of the weekday for each date and display the results in column B.
We can create the following macro to do so:
Sub FindWeekdayName()
Dim i As Integer
For i = 2 To 9
Range("B" & i) = WeekdayName(Weekday(Range("A" & i)))
Next i
End Sub
When we run this macro, we receive the following output:
Column B displays the name of the weekday for each date in column A.
For example:
- 1/1/2023 is on a Sunday.
- 1/4/2023 is on a Wednesday.
- 2/23/2023 is on a Thursday.
And so on.
Note: You can find the complete documentation for the VBA WeekdayName function here.
Additional Resources
The following tutorials explain how to perform other common tasks in VBA:
How to Compare Dates in VBA
How to Convert Date to Week Number in VBA
How to Calculate Days Between Two Dates in VBA