date calculation

G

Guest

Following is code for calculating only workdays - not weekends/holidays (I
have code for the holidays) based upon the current date and a variable for
the number of days to calculate. I can't get the result and get a #Name?
where the result should go. I'm wondering if I don't have the appropriate
references marked.

Any suggestions?

Public Function GetTargetDate(ByRef indate As Date, ByRef DaystoCompletion
As Integer) As Date
Dim intWorkDayCount As Integer
Dim dtStart As Date
Dim dtEnd As Date
Dim dtCurrent As Date
Dim intNumDays As Integer

intWorkDayCount = 0
dtEnd = DateAdd("yyyy", 2, indate)

For dtCurrent = indate To dtEnd
Select Case DatePart("w", dtCurrent)
Case vbMonday, vbTuesday, vbWednesday, vbThursday, vbFriday
If Not IsHoliday(dtCurrent) Then
intWorkDayCount = intWorkDayCount + 1
End If
End Select
If intWorkDayCount = DaystoCompletion Then Exit For
Next dtCurrent
GetTargetDate = dtCurrent
End Function
 
G

Guest

Try passing dtCurrent off to another local dateVar before you jump out of the
For loop. Return that dateVar instead of dtCurrent.
 

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

Top