VB Workdays

Nomis_Eswod

Board Regular
Joined
Jul 27, 2005
Messages
153
Hi,

I have a form with some text boxes on it. In one text box is a date, this is automatically populated with the days date when it is entered. Another box contains a number, which is the amount of days expected to complete a task. What I do is add the number to the date to get another date so I know when I need to complete the task by.

What I want to do is calculate the future date in working days, i.e. not counting weekends. Do you know if there is anyway to do this in VBA?

Thanks,
Me
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
In it's simplest form...

Code:
Function GetFinishDate(StartingDate As Date, Days As Double) As Date
    Dim OffDaysCnt As Double
    
    Do
        If Weekday(StartingDate, vbSaturday) > 2 Then Days = Days - 1
        StartingDate = StartingDate + 1
    Loop While Days > 0
    
    GetFinishDate = DateAdd("d", OffDaysCnt - 1, StartingDate)
End Function

Tweek it to not include the first day and to take into account holidays if you need to...
 
Upvote 0

Forum statistics

Threads
1,214,881
Messages
6,122,074
Members
449,064
Latest member
MattDRT

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