Quantcast
Channel: Herbert Julius Garonfolo »» Coding
Viewing all articles
Browse latest Browse all 6

Excel VBA: Finding the Second Last Sunday of the Month

$
0
0

In one of my projects, I needed to schedule an event on the second last Sunday of each month, so I wrote up a small function in Excel to help me with this:

Function secondlastsunday(maaned)
secondlastsunday = DateSerial(Year(Date), maaned + 1, 0)
secondlastsunday = secondlastsunday - Weekday(secondlastsunday, vbMonday) - 7
End Function

The function takes the month as a number between 1 and 12.
So in Excel, you would choose a cell and input:

=secondlastsunday(10)

to get the second last Sunday of October (i.e. October 21st, 2012).

You can also use the function this way with a particular date

=secondlastsunday(month("16/09/2012"))

or you could also just use a cell reference.


Viewing all articles
Browse latest Browse all 6

Trending Articles