Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Fiscal Quarter code not working

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

--
Robert
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Fiscal Quarter code not working

datepart("m",0) = 12

Might try wrapping it in an 'if x is numeric' type of clause

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Fiscal Quarter code not working

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

--
HTH...

Jim Thomlinson


"Robert" wrote:

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

--
Robert

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default Fiscal Quarter code not working

Jim, thanks but I tried this and it still doesn't seem to work.
--
Robert


"Jim Thomlinson" wrote:

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

--
HTH...

Jim Thomlinson


"Robert" wrote:

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

--
Robert

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Fiscal Quarter code not working

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

--
HTH...

Jim Thomlinson


"Robert" wrote:

Jim, thanks but I tried this and it still doesn't seem to work.
--
Robert


"Jim Thomlinson" wrote:

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

--
HTH...

Jim Thomlinson


"Robert" wrote:

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

--
Robert

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a specific date to a fiscal quarter ? RichNYC Excel Discussion (Misc queries) 10 November 26th 07 03:35 PM
Fiscal Quarter Conversion Andrew Excel Worksheet Functions 7 April 3rd 07 08:26 PM
fiscal quarter conversion Ted McCastlain Excel Discussion (Misc queries) 3 September 6th 06 10:25 PM
fiscal quarter data validation Doug Glancy Excel Worksheet Functions 2 August 12th 05 12:12 AM
display quarter and fiscal year D S K Excel Programming 1 May 7th 04 03:44 PM


All times are GMT +1. The time now is 05:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"