Weekday function

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

Does VBA have a function which accepts an integer
input between 1 and 7, which returns a string value
to represent the corresponding day of the week??

For example, if you give the function an integer value
of 1, then it should give back a string of "Sunday"...
and the number 7 should return "Saturday".

I know I can easily write my own function, but I'm
curious if VBA provides a function already. No
need for me to reinvent the wheel.

thank you
 
Don't think so, you would need to write one

Function MyWeekDay(DayNum As Long) As String
Dim Days As Variant

MyWeekDay = Format(Date - (Weekday(Date) - 2) + DayNum - 2, "ddd")
End Function


HTH

Bob
 
Hello Robert,

Via VBA you can use
Format(n,"ddd")
or
Application.Worksheetfunction.Text(n,"ddd")
where n is your number 1, 2, 3, ... (starting with 1 = Sunday)

Regards,
Bernd
 
I just found out that VBA does actually provide a function of it's
own. It is called "WeekdayName()"

It works as follows:

WeekdayName(1) == returns "Sunday"
WeekdayName(1) == returns "Sunday"
WeekdayName(1) == returns "Sunday"
WeekdayName(1) == returns "Sunday"
WeekdayName(1) == returns "Sunday"
WeekdayName(1) == returns "Sunday"
 
I mean:

WeekdayName(1) == returns "Sunday"
WeekdayName(2) == returns "Monday"
WeekdayName(3) == returns "Tuesday"
WeekdayName(4) == returns "Wednesday"
WeekdayName(5) == returns "Thursday"
WeekdayName(6) == returns "Friday"
WeekdayName(7) == returns "Saturday"
 
Aah yes, I recall seeing that once now you mention, just never had cause to
use it.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

WeekNum Trouble 4
which weekday? 1
Code Optimization 0
How to write a VBA function which returns an integer 5
vlookup in VBA 3
Xth Weekday of the Month/Year 2
Date Removal 2
custom function for the day of the week 3

Back
Top