Q: Finding the first monday of a month
I'm relatively new at Visual Basic and I have a question that I haven't been able to find a solution to yet. I was wondering if you could help. I am trying to identify the first Monday of each month. Using the following: MYWEEK = Format(Now, "ww") WEEK_NUM = DatePart("ww", MYWEEK I can get what week it is in the year but then how do I know if that week falls within which month and is the identified week the first week of that month and if so how do I format it so that it evaluates it as Monday or not? Any ideas. Thanks for your help! BTW I really like your web site - very informative!! Erick Larson Mid-Columbia Medical Center erickl@mcmc.net
A: 'make a new project 'add a form with a commandcontrol 'insert the next code 'press F5 Private Sub Command1_Click() MsgBox "week " & DatePart("ww", Now) & " of " & Year(Now) MsgBox "the month is " & ReplaceMonth(month(Now)) MsgBox "the first monday is " & GetMonday End Sub Private Function ReplaceMonth(month As Byte) As String Select Case month Case 1 ReplaceMonth = "januari" Case 2 ReplaceMonth = "februari" Case 3 ReplaceMonth = "march" Case 4 ReplaceMonth = "april" Case 5 ReplaceMonth = "mai" Case 6 ReplaceMonth = "juni" Case 7 ReplaceMonth = "juli" Case 8 ReplaceMonth = "august" Case 9 ReplaceMonth = "september" Case 10 ReplaceMonth = "oktober" Case 11 ReplaceMonth = "novembre" Case 12 ReplaceMonth = "decembre" End Select End Function Private Function GetMonday() As String Dim bX As Byte Dim dDate As Date For bX = 1 To 7 dDate = CStr(bX) & "-" & month(Now) & "-" & Year(Now) If DatePart("w", dDate) = vbMonday Then GetMonday = dDate: Exit Function Next bX End Function Return