Sunday 8 April 2018

How to find next working day in Excel VBA macros


VBA doesn't have an inbuilt function to find the next working day / previous working day.

You can use below code to find the next working day in VBA.


Function GetNextWorkingDay(InptDate As Date)
GetNextWorkingDay = InptDate + IIf(Weekday(InptDate) > 5, 9 - Weekday(InptDate), 1)
End Function


Note : Alternatively You can use the Workday function in Excel if you are using a higher version of Excel as explained in below link. But if you are creating a product which is going to be used in multiple versions of Excel, you should use above code.

http://macromatician.blogspot.in/2018/03/workday-formula-using-excel-vba-how-to.html

No comments:

Post a Comment