Fiscal Quarter code not working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This code works when x = a date, but if the cell is blank it displays a "2"
not the error message Case Else should display. Any ideas why?

Function GetFiscalQuarter(ByVal x As Date) 'this works as variant also
Dim Qtr As Date 'this works as integer or variant
Qtr = DatePart("m", x)

Select Case Qtr
Case 7, 8, 9
Qtr = "1"
Case 10, 11, 12
Qtr = "2"
Case 1, 2, 3
Qtr = "3"
Case 4, 5, 6
Qtr = "4"
Case Else
Qtr = "error" 'this doesn't work at all!!!!
End Select

GetFiscalQuarter = Qtr

End Function
 
It is a lot easier than that. VBA recognizes q as a vaid format.

Function GetFiscalQuarter(ByVal x As Date) as Integer
GetFiscalQuarter = Cint(fomat(x, "q"))
End Function
 
It would work better if I knew how to type... :-)

Format should be Format...

Function GetFiscalQuarter(ByVal x As Date) As Integer
GetFiscalQuarter = CInt(Format(x, "q")) 'Typo...
End Function
 
Back
Top