+ Reply to Thread
Results 1 to 1 of 1

Define the function Quarter to be used in your Excel

Hybrid View

  1. #1
    Valued Forum Contributor adyteo's Avatar
    Join Date
    01-10-2013
    Location
    Calgary
    MS-Off Ver
    Excel 2010
    Posts
    540

    Lightbulb Define the function Quarter to be used in your Excel

    You could create an add-in (".xla"), that you load it every time you open excel, with formulas you use often that are not defined by Microsoft but by you.

    e.g. function Quarter(date, type)

    What the below code does is to take the date and convert it into a string with a certain format:
    if type is 0, then it will be e.g. CY14Q1
    if type is 1, then it will be e.g. FY14Q1
    Function Quarter(datDate As Date, intType As Byte) As String
    
    Dim strQ As String
    Dim strType As String
    
    'strType = 0 for CY (Calendar Year) or 1 for FY (Fiscal Year)
    'datDate = 01.01.2014
    
    If intType = 0 Then strType = "CY" & Right(Year(datDate), 2)
    If intType = 1 Then
        If Month(datDate) > 3 Then
            strType = "FY" & Right(Year(datDate) + 1, 2)
        Else
            strType = "FY" & Right(Year(datDate), 2)
        End If
    End If
    
    If intType <> 0 And intType <> 1 Then Err.Raise (vbObjectError + 513)
    
    Select Case Month(datDate)
    Case 1 To 3
        If intType = 0 Then strQ = "Q1"
        If intType = 1 Then strQ = "Q4"
    Case 4 To 6
        If intType = 0 Then strQ = "Q2"
        If intType = 1 Then strQ = "Q1"
    Case 7 To 9
        If intType = 0 Then strQ = "Q3"
        If intType = 1 Then strQ = "Q2"
    Case 10 To 12
        If intType = 0 Then strQ = "Q4"
        If intType = 1 Then strQ = "Q3"
    End Select
    
    Quarter = strType & strQ
    
    End Function
    Good luck
    Last edited by adyteo; 03-07-2014 at 10:49 AM. Reason: PS I corrected the result of the function from FY2014 to FY14Q1
    Click on the star if you think I helped you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Put Define Name in IF function
    By Shermaine2010 in forum Excel General
    Replies: 3
    Last Post: 08-19-2011, 05:08 AM
  2. Excel 2003: Define custom Hyperlink in cell that contains function
    By myCellEqualsNull in forum Excel General
    Replies: 2
    Last Post: 04-07-2010, 04:01 AM
  3. End of Quarter Function
    By covershaker in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-21-2010, 01:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1