Getting the Day Number Related To A (Text) Day Of The Week (eg "Sat" = 7)

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
VBA function WEEKDAY(date) returns the the number relating to the day of the week. eg Sun = 1, Mon = 2 etc.
Suppose I have a day text value, like Sat. What is a VBA solution to getting it's value 7?

I could do an If Elseif Then routine, but I'm hoping their might be a shorter method.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
One way is to create your own Custom Function in VBA like this:
VBA Code:
Function GetWeekday(d As Variant) As Integer

    Select Case d
        Case "Sun."
            GetWeekday = 1
        Case "Mon."
            GetWeekday = 2
        Case "Tue."
            GetWeekday = 3
        Case "Wed."
            GetWeekday = 4
        Case "Thu."
            GetWeekday = 5
        Case "Fri."
            GetWeekday = 6
        Case "Sat."
            GetWeekday = 7
        Case Else
            GetWeekday = 0
    End Select
    
End Function

You can reference it like any other Excel function in VBA or on the worksheet, i.e.
VBA Code:
Sub Test()
    MsgBox GetWeekday("Sat.")
End Sub
 
Upvote 1
Solution
Thanks Joe. A very clever and practical approach. Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top