Date VBA Code

D

Darla

Help! I am trying to figure out VBA coding. I need to
figure the difference between the day something comes into
our shop and the day it leaves. This needs include only
workdays. I found this code that takes out weekends but
not holidays. I'm also not sure how to put my field names
into it so it can calculate. Following is the code.
Thanks for any help you can give this novice!!!

Function Work_Days(BegDate As Variant, EndDate As Variant)
As Integer
' Note that this function does not account for holidays.
Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer

BegDate = DateValue(BegDate)

EndDate = DateValue(EndDate)
WholeWeeks = DateDiff("w", BegDate, EndDate)
DateCnt = DateAdd("ww", WholeWeeks, BegDate)
EndDays = 0
Do While DateCnt < EndDate
If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat"
Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = WholeWeeks * 5 + EndDays
End Function
 

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