Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Day of week calculation

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I am tring to develop a day of week calculation function to identify the day of the week. I am getting a compile error Argument not optional. Any help would be appreciated.

Code:
Sub Last_Monday(vDate As Date)
     'if today is Monday, then return today's date
    If Weekday(vDate, vbSunday) = 2 Then
        Last_Monday = vDate
    Else
        Last_Monday = vDate - Weekday(vDate, vbSunday) + 2
    End If
End Sub
 



Hi,
Code:
[b]Function[/b] Last_Monday(vDate As Date)
     'if today is Monday, then return today's date
    If Weekday(vDate, vbSunday) = 2 Then
        Last_Monday = vDate
    Else
        Last_Monday = vDate - Weekday(vDate, vbSunday) + 2
    End If
End [b]Function[/b]

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Furthermore:
Function Last_Monday(vDate As Date) As Date


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I made this change now I can't use the sub designation how do I use this function within another macro?
 
WhatEverYouWantAsLastMonday = Last_Monday(WhatEverTheTestedDateIs)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You may want to explicitly declare your function as Public also.
Are you sure your logic is correct? If vDate is a Sunday, then you'll get the next day. Are you sure you don't mean:
Code:
Public Function Last_Monday(vDate As Date) As Date
    Last_Monday = vDate - Weekday(vDate, vbMonday) + 1
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top