Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VB scripts to calculate as NetWorkdays

I tried to write a macro by using VB Editor. I need to calculate the total
working days (same as the NetWorkdays function in the Excel). I will
appreciate if you have any sampel code or any hit on how...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default VB scripts to calculate as NetWorkdays

?application.run("networkdays",date,date + 20)

gives 15

--
Kind regards,

Niek Otten

Microsoft MVP - Excel
"ciccia" wrote in message
...
I tried to write a macro by using VB Editor. I need to calculate the total
working days (same as the NetWorkdays function in the Excel). I will
appreciate if you have any sampel code or any hit on how...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default VB scripts to calculate as NetWorkdays

Hi,

what about this example:

Function Networkdays2(start_date As Date, end_date As Date, _
Optional holidays As Variant) As Long
Dim ToSun As Long, FromSun As Long, Days As Long
Dim i As Long, n As Long
Dim varHolidays As Variant, v As Variant
Dim x As Date, a() As Date

On Error GoTo ErrorHandler

If start_date end_date Then GoTo ErrorHandler

ToSun = 7 - Weekday(start_date + 5)
FromSun = Weekday(end_date) - 1
Days = Int((end_date - (start_date - 1) - ToSun) / 7) * 5
If ToSun 2 Then ToSun = ToSun - 2 Else ToSun = 0
If FromSun 5 Then FromSun = 5
Days = Days + ToSun + FromSun

If Not IsMissing(holidays) Then
If TypeName(holidays) = "Range" Then
Set varHolidays = holidays
ElseIf IsArray(holidays) Then
varHolidays = holidays
Else
varHolidays = Array(holidays)
End If
For Each v In varHolidays
If IsDate(v) Then
x = CDate(v)
For i = 1 To n
If a(i) = x Then Exit For
Next
If i n Then
n = n + 1
ReDim Preserve a(1 To n)
a(n) = x
If x = start_date And x <= end_date And _
Weekday(x + 1) 2 Then Days = Days - 1
End If
End If
Next
End If
Networkdays2 = Days
Exit Function

ErrorHandler:
Networkdays2 = -1
Exit Function
End Function

--
HTH,

okaizawa


ciccia wrote:
I tried to write a macro by using VB Editor. I need to calculate the total
working days (same as the NetWorkdays function in the Excel). I will
appreciate if you have any sampel code or any hit on how...

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
delete scripts AND Excel Worksheet Functions 1 March 20th 09 01:16 PM
Forumlas or scripts? Gor_yee Excel Discussion (Misc queries) 0 October 16th 06 01:53 PM
SQL Scripts in Excel markus Excel Discussion (Misc queries) 1 October 13th 06 12:39 PM
need networkdays to calculate for all users. Deb Bagby Setting up and Configuration of Excel 0 November 1st 05 04:22 PM
Macintosh and VB Scripts ccoverne Excel Programming 2 November 29th 04 09:11 PM


All times are GMT +1. The time now is 07:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"