Developer

Use VBA to return the next Saturday

Let VBA schedule your next weekend off. Just use this simple VBA function to return the date of the next Saturday.

Looking ahead is part of most projects. Whether you're scheduling downtime or a special event, knowing the date of the next Saturday can come in handy. In that case, the following VBA function procedure should help:

Public Function FindNextSaturday(dte As Date) As Date
  'Return the first Saturday following dte
   FindNextSaturday = dte + (7 - Weekday(dte))
End Function

Simply pass a date to the function — but be sure to delimit it properly using the # character as follows:

#09/30/09#

The dte + (7 - Weekday(dte)) component adds the number of days between the passed date and the next Saturday to the current date — the result being the next Saturday. This function should work in any application that supports VBA.

About Susan Harkins

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

Editor's Picks

Free Newsletters, In your Inbox