Categories
How-To Public

Excel: Custom VBA Function to Return Quarter from Date


Function fnQuarterFromWeek(varDate)

'Declare variables
Dim varMonth

'Get month from date
varMonth = Month(varDate)

'Set quarter based on month
If varMonth < 3 Then varQuarter = 1 If varMonth > 3 Then varQuarter = 2
If varMonth > 6 Then varQuarter = 3
If varMonth > 9 Then varQuarter = 4

'Return value
fnQuarterFromWeek = Year(varDate) & "-" & varQuarter

End Function

Leave a Reply

Your email address will not be published. Required fields are marked *