Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-04-2021, 11:13 PM
gmayor's Avatar
gmayor gmayor is offline Need a Function with Select Case for the Holidays Windows 10 Need a Function with Select Case for the Holidays Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Well it could certainly be simplified
Code:
Option Explicit

Sub Macro6()
'The Idea is to Find Weekdays, then find Holidays that are Weekdays
'Graham Mayor - https://www.gmayor.com - Last updated - 05 Jan 2021
Dim Count As Integer
Dim TestDay As Date
Dim sMessage As String
Dim vHolidays As Variant
Dim i As Integer, j As Integer
Dim oRng As Range
Dim dDate As DataObject

vHolidays = Array("01/01/21", "01/02/21", "01/30/21")    'add the holidays to the array

    Count = 14
    TestDay = Date    'CDate("01/01/21")

    For i = 1 To 14
        If Weekday(TestDay + i) = 1 Or Weekday(TestDay + i) = 7 Then
            Count = Count + 1
            'if added day is at the weekend add another day
            If Weekday(TestDay + Count) = 1 Or Weekday(TestDay + Count) = 7 Then Count = Count + 1
        End If
    Next i

    For j = 0 To UBound(vHolidays)
        If TestDay = CDate(vHolidays(j)) Then
            Count = Count + 1
            'probably unnecessary but if added day is at the weekend add another day
            If Weekday(TestDay + Count) = 1 Or Weekday(TestDay + Count) = 7 Then Count = Count + 1
        End If
    Next j

    TestDay = DateAdd("d", Count, TestDay)     'Add count to TestDay

    Selection.TypeText TestDay    'optional as the date is written to the clipboard

    Set dDate = New DataObject
    dDate.SetText TestDay
    dDate.PutInClipboard

    sMessage = "14 Working Days from Today - " & TestDay
    MsgBox sMessage, vbInformation, "Add working days"
    Set dDate = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a Function with Select Case for the Holidays Can Select Case be used to defined the Value of an item in a drop down list? mbews Word VBA 10 10-08-2020 05:04 AM
Need a Function with Select Case for the Holidays Toggle between upper case, lower case, etc... by one single macro on a Mac, to emulate Shift + F3 on gloub Word VBA 2 01-30-2019 12:40 PM
Need a Function with Select Case for the Holidays SENDKEYS with vbYesNoCancel and Select Case kiwimtnbkr Word VBA 31 06-11-2018 04:56 AM
Need a Function with Select Case for the Holidays Use function to select another worksheet eugeneradial Excel 2 04-27-2017 04:53 AM
Help with Case and Select case brent chadwick Word VBA 34 10-18-2015 02:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft