![]() |
#1
|
|||
|
|||
![]()
Hello there,
I'm trying to create a macro for a Microsoft Word document that returns the number of the business days (i.e. no Sunday and Saturday) between an inputted start date and the current date. I tried to search for/write code that excludes weekends and insert it into the following macro, but have been unsuccessful thus far. Your help would be much appreciated! Sub CalculateDateDifference() Dim xStartDate As Date Dim xEndDate As Date Dim xDay As Long On Error Resume Next xStartDate = InputBox("Enter the start date", "Start Date", "") xEndDate = Date If (InStr(1, Str(xStartDate), ":") > 0) Or (InStr(1, Str(xEndDate), ":") > 0) Then MsgBox "please input current date", vbInformation, "Date Calculation" Exit Sub End If xDay = DateDiff("d", xStartDate, xEndDate) MsgBox "There are " & xDay & " days from " & xStartDate & " to " & xEndDate & vbCrLf, vbInformation, "Date Calculation" End Sub |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
PowerStar | Excel | 7 | 06-07-2021 04:03 AM |
Formula for calculating dates based on Business Days | jthomas666 | Excel | 2 | 03-02-2020 09:05 AM |
Default How to automatically Calculate number of days between two dates? | wcngu1 | Word | 6 | 10-24-2019 04:20 AM |
![]() |
Artboy34 | Excel | 3 | 01-28-2016 09:47 AM |
Calculating 6.5hr work days | altja | Project | 3 | 02-10-2014 03:11 PM |