![]() |
|
|
|
#1
|
|||
|
|||
|
Couple of things.
1. As a new coder you have the same tendency as I had. You declare a lot of extraneous variables and you seem stuck on "Selection." Learn to use the range object and unless needed for clarity minimize variables. Code:
Option Explicit Sub Macro1() Dim oRng As Range Set oRng = Selection.Range oRng.Text = Format(DateDue(Date, 15), "mm-dd-yyyy") 'I assume you want to copy this resulting date value to the clipboard for use later. 'Otherwise this next line is not needed. oRng.Copy Application.StatusBar = "Fifteen Days from Today " & oRng.Text End Sub Code:
Public Function DateDue(ByVal vDate As Date, ByVal iDays As Variant) As Variant 'Graham Mayor - http://www.gmayor.com - Last updated - 14 May 2017 'Add weekdays to date - from Monday if date falls at weekend Dim iCount As Integer DateDue = Null If IsNull(vDate) Or IsNull(iDays) Then GoTo lbl_Exit End If Select Case Weekday(vDate) Case Is = 1 ' Sunday vDate = DateAdd("d", 1, vDate) iCount = 0 Case Is = 7 ' Saturday vDate = DateAdd("d", 2, vDate) iCount = 0 Case Else iCount = Weekday(vDate) - 2 End Select 'Note, Graham's code actually returns the non-weekday 1 day after the span passed by iDays iDays = iDays + iCount 'If you want the "iDay" use: 'iDays = iDays + iCount - 1 vDate = DateAdd("d", iCount * -1, vDate) DateDue = DateAdd("d", iDays Mod 5, DateAdd("ww", Int(iDays / 5), vDate)) lbl_Exit: Exit Function End Function |
|
#2
|
||||
|
||||
|
Quote:
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Counting the difference in days within multiple groups
|
wheddingsjr | Excel | 2 | 03-28-2017 07:38 AM |
| Sum Function over Today +/- 60 Days | gabeha | Excel | 2 | 09-12-2014 01:13 AM |
| Using Outlook Today Calendar Days | cwksr | Outlook | 0 | 08-13-2014 10:57 AM |
| Conditional formatting of Today +21 days? | SHERMAN | Excel | 3 | 12-20-2010 08:08 AM |
| Creating an Auto-Calc'd Date? Today+7 Days? | SoCalTelephone | Word | 0 | 10-06-2010 10:27 AM |