Determine Next/Previous Weekday

This function returns week identifier information, such as Week Beginning/Ending date, and makes it more generic to return a date of any previous or following weekday. You can use this function in VB5 and VBA5; with minor modifications to the optional arguments, you can also use it in VB3 and VB4:

 Public Function SpecificWeekday(d As Date, _	Optional ByVal WhatDay As Byte = _	vbSaturday, Optional ByVal GetNext _	As Boolean = True) As Date	'Purpose: Returns a date of the 	'Next/Previous specific weekday for a given date	' Input:		d - Date for which next/previous 	'			weekday is needed 	'			WhatDay - optional (byte) 	'			argument (default = vbSaturday)	'			specifying what weekday to find	'			GetNext - optional (Boolean) 	'			argument: True for 	'			Next(default), False for Previous	'Output:		Date of the next/previous specific weekday	'Note:		If both optional arguments are 	'			omitted, returns Week-Ending Date	'			If passed date (d) falls on the 	'			same weekday as WhatDay, the 	'			function returns the passed date 	'			unchanged.	Dim iAdd As Integer	iAdd = (WhatDay - WeekDay(d))	If GetNext Then		SpecificWeekday = DateAdd("d", IIf(_			iAdd >= 0, iAdd, 7 + iAdd), d)	Else		SpecificWeekday = DateAdd("d", IIf(_			iAdd <= 0, iAdd, iAdd - 7), d)	End IfEnd Function
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: