Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Weekday function

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Weekday function

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

"Robert Crandal" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 806
Default Weekday function

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Weekday function

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"


"Bob Phillips" wrote in message
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Weekday function

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"



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Weekday function

Nice, that would work just as well too!

Thank you everyone!


"Bernd P" wrote in message
...
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)


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Weekday function

Aah yes, I recall seeing that once now you mention, just never had cause to
use it.

Bob

"Robert Crandal" wrote in message
...
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"


"Bob Phillips" wrote in message
...
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





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 806
Default Weekday function

Hello Robert,

Good one.

Regards,
Bernd
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weekday function Not right Wanna Learn Excel Discussion (Misc queries) 1 May 2nd 08 03:01 PM
Weekday function? Cam Excel Discussion (Misc queries) 1 February 26th 08 08:58 PM
Using Weekday function with no add-ins Basil Excel Programming 3 April 30th 07 06:20 PM
WEEKDAY() function: display TEXT not numeric weekday tom Excel Discussion (Misc queries) 3 November 21st 06 04:32 PM
Weekday Function John Excel Worksheet Functions 2 January 7th 05 11:39 AM


All times are GMT +1. The time now is 06:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"