Hi,
The following formula:
=4+(DAY(B4-DAY(B4)+35)<WEEKDAY(B4-DAY(B4)+4))
correctly calculates the number of Wednesdays in a month but I am having some difficulty in getting this to work in VBA. When I put this into VBA the results are not the same so obviously I cannot just paste this formula in as code. I am still learning Excel vba so hope that this will be an easy one for someone more experienced than me.
This is my code so far:
--------------------------------------------------------------
Private Sub SetupPlanner()
Dim i As Integer
Dim CurrMnth As Date
Dim NoOfWeeks As Integer
Dim StartDate As Date
Dim EndDate As Date
Dim ProjMnths As Integer
StartDate = Worksheets("Sheet2").Range("B5:B5").Value
EndDate = Worksheets("Sheet2").Range("B6:B6").Value
ProjMnths = DateDiff("m", StartDate, EndDate)
For i = 0 To ProjMnths
StartDate = Worksheets("Sheet2").Range("B5:B5").Value
CurrMnth = DateAdd("m", i, StartDate)
NoOfWeeks = 4 + (Day(CurrMnth - Day(CurrMnth) + 35) < Weekday(CurrMnth - Day(CurrMnth) - 4))
Debug.Print CurrMnth, NoOfWeeks
' Debug.Print NoOfWeeks
Next i
End Sub
---------------------------------------------------------------------------------
In essence I'm trying to create a spreadsheet for each of our projects which has a start date and and estimated completion date. I will then loop through each of the months for the duration of the project, calculate the no. of weeks in each month and then set up each week as a column in the spreadsheet. However I am stuck in the early stages of the process.
Thanking you in advance for any assistance/advice.
Gerry
Bookmarks