|  

» Adding a Custom Function That Returns the Quarter Number

To add a custom function to a Module in the Personal Macro Workbook (To learn more about creating a Personal Macro Workbook.

1. Press Alt+F11 to open the VBE.
2. Double-click a Module name in the Personal Macro Workbook, or insert a new Module into the Personal Macro Workbook by selecting Module from the Insert menu.
3. Enter the following code lines into the Module:

Function QuarterNum(Enter_Date)
QuarterNum = DatePart ("q", Enter_Date)
End Function


To test the Custom Function:

1. Select any empty cell and press Shift+F3 to open the Paste Function dialog box.
2. In the User Defined category, select QuarterNum, and then click OK.
3. In the Function Arguments dialog box, enter the address of a cell containing a date, and click OK.
Screenshot // Adding a Custom Function That Returns the Quarter Number
Adding a Custom Function That Returns the Quarter Number

Rate This Tip
12 34 5
Rating: 3.44     Views: 47685
For British tax year quarter, or corporate quarter
Glenn Bumford  Posted on: 31-12-1969
For purposes where the quarter should be 1 for April-May-June, and so on( for example, for a financial year ), then simply alter this custom function so that it reads: QuarterNum = ((DatePart("q", Enter_Date) + 2) Mod 4) + 1 and it will return financial year quarter.
Hlookup
Ernest  Posted on: 31-12-1969
can you kindly tell me what Hlookup is and ho to use it in Excel?
Reply: Hlookup - Ernest from Ghana wrote on July 25, 2003 9:52 AM EST
Alan  Posted on: 31-12-1969
Hi Ernest,

Have you read the help screens in Excel?

If so, what specific questions do you have - what is not clear?

Thanks,

Alan.
Custom function for calculating quarter
mohamed Yahya  Posted on: 31-12-1969
is there any way to save custom function as user-defind
function permenantly. (unique) i.e to use it at any time
with any woorksheet just like other functions.
Reply: Custom function for calculating quarter - mohamed Yahya from Saudi Arabia wrote on August 25, 2003 9:51 AM EST
Alan  Posted on: 31-12-1969
Hi Mohamed,

If you want a UDF (or an code) to be available to a given user at all times regardless of the workbook they are using, then put that code in their PERSONAL.XLS file.

If you want the code to always be available within a given workbook, regardless of the user, then you must put the code in that workbook.

As far as I know, it is impossible to do both, unless you are Microsoft (!)

HTH,

Alan.
Name
Comment Title
Comments