View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
mangesh_yadav[_250_] mangesh_yadav[_250_] is offline
external usenet poster
 
Posts: 1
Default Using VBA to create a Networkdays function


Function myWorkDay(myDate As Date, AddDays, LeaveDay)

If AddDays = 0 Then
myWorkDay = myDate
Exit Function
End If

For j = 1 To 7
If Choose(j, "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday") = LeaveDay Then
LD = j
End If
Next j


i = 1
Do While i <= AddDays
myWorkDay = myDate + i
If WorksheetFunction.Weekday(myWorkDay) = LD Then
AddDays = AddDays + 1
End If
i = i + 1
Loop

End Function

Usage:
=myWorkDay(A1,B1,C1)
Where A1 contains a date, B1 contains nos of days to add, C1 contains
the day to leave out. E.g "Sunday"


Mangesh


--
mangesh_yadav
------------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...o&userid=10470
View this thread: http://www.excelforum.com/showthread...hreadid=376705