Results 1 to 2 of 2

Thread: Are you a Maths Hero...?

  1. #1

    Thread Starter
    Hyperactive Member SjR's Avatar
    Join Date
    Jul 2001
    Location
    Birmingham, UK
    Posts
    336

    Lightbulb Are you a Maths Hero...?

    Hi everyone.

    I have a bit of a maths query (unless there is a VB function that will sort this for me - that would be great )
    I'm reading the current date from the system, and I'd like to calculate the last complete quarter.
    Eg. We're in August 2001 therefore the *last complete* quarter was Q2 2001. It doesn't matter what the format is, but basically I'd like to calculate the following:
    If Month = 1, then Quarter = 4 and Year = Year-1
    If Month = 7, then Quarter = 2 and Year = Year
    If Month = 11, then Quarter = 3 and Year = Year
    Hope this makes sense...
    Any help would be very, very much appreciated.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Something like this? I've only tested it for this month (obviously)
    VB Code:
    1. Dim strQtr As String
    2. Dim strYear As String
    3.  
    4. If Format(Date, "mm") <= 3 Then
    5.     strQtr = "Q4"
    6.     strYear = CStr(Format(DateAdd("y", -1, Date), "yyyy"))
    7. ElseIf Format(Date, "mm") <= 6 Then
    8.     strQtr = "Q1"
    9.     strYear = CStr(Format(Date, "yyyy"))
    10. ElseIf Format(Date, "mm") <= 9 Then
    11.     strQtr = "Q2"
    12.     strYear = CStr(Format(Date, "yyyy"))
    13. ElseIf Format(Date, "mm") <= 12 Then
    14.     strQtr = "Q3"
    15.     strYear = CStr(Format(Date, "yyyy"))
    16. End If
    17.  
    18. MsgBox strQtr & ", " & strYear

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width