Exclude weekends

Blunder1

Active Member
Joined
Jun 2, 2010
Messages
250
Hi,

Is there any code for VBA where it will count between to dates and excludes weekends? I looked around and it seems to use a function called 'NETWORKDAYS', but this appears to be something you need to set up within excel which i would prefer to avoid.

Thanks

Blunder1
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
There is a Formula called NetWorkDays if this isn't available when you look at the Functions you would need to add in the Analysis Pack which can be found under the Tools Menu and Add In if using 2003. Then when you look at the Functions you will find it has been added.

No VBA required.
 
Upvote 0
Thank you, Trevor. Many people will use this macro, some with very little Excel skills. On this basis i need to do the count within VBA as oppose to functions.

Any help would be appreciated.

Thanks
 
Upvote 0
You could use NETWORKDAYS in VBA like this

Code:
Sub test()
Dim d1 As Long, d2 As Long, diff As Long
d1 = DateSerial(2011, 8, 16)
d2 = DateSerial(2011, 8, 26)
diff = Evaluate("NETWORKDAYS(" & d1 & "," & d2 & ")")
MsgBox diff
End Sub
 
Upvote 0
Perhaps you can use this:-
This code loops through dates in column "A", if Week day date found then the code places the word "Weekday" in column "B" and if weekend date then "WeekEnd" is displayed .
Code:
Dim Rng As Range, Dn As Range
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
For Each Dn In Rng
    If Not Weekday(Dn) = 1 And Not Weekday(Dn) = 7 Then
        Dn.Offset(, 1) = "Weekday"
    Else
        Dn.Offset(, 1) = "Weekend"
    End If
Next Dn
Mick
 
Upvote 0
Is there a difference or some distinction b/w using the Evaluate method as opposed to using Application.WorksheetFunction.xxxx?
 
Upvote 0
In Excel 2003 and earlier you have to use Evaluate with functions from the Analysis Toolpak like NETWORKDAYS.

In Excel 2007+ you can use WorksheetFunction.Networkdays
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,484
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top