Skip to content
Felix
  • Topics
    • My List
    • Felix Guide
    • Asset Management
    • Coding and Data Analysis
      • Data Analysis and Visualization
      • Financial Data Tools
      • Python
      • SQL
    • Credit
      • Credit Analysis
      • Restructuring
    • Financial Literacy Essentials
      • Financial Data Tools
      • Financial Math
      • Foundations of Accounting
    • Industry Specific
      • Banks
      • Chemicals
      • Consumer
      • ESG
      • Insurance
      • Oil and Gas
      • Pharmaceuticals
      • Project Finance
      • Real Estate
      • Renewable Energy
      • Technology
      • Telecoms
    • Introductory Courses
    • Investment Banking
      • Accounting
      • Financial Modeling
      • M&A and Divestitures
      • Private Debt
      • Private Equity
      • Valuation
      • Venture Capital
    • Markets
      • Economics
      • Equity Markets and Derivatives
      • Fixed Income and Derivatives
      • Introduction to Markets
      • Options and Structured Products
      • Other Capital Markets
      • Securities Services
    • Microsoft Office
      • Excel
      • PowerPoint
      • Word & Outlook
    • Professional Skills
      • Career Development
      • Expert Interviews
      • Interview Skills
    • Risk Management
    • Transaction Banking
    • Felix Live
  • Pathways
    • Investment Banking
    • Asset Management
    • Equity Research
    • Sales and Trading
    • Commercial Banking
    • Engineering
    • Operations
    • Private Equity
    • Credit Analysis
    • Restructuring
    • Venture Capital
    • CFA Institute
  • Certified Courses
  • Ask An Instructor
  • Support
  • Log in
  • Topics
    • My List
    • Felix Guide
    • Asset Management
    • Coding and Data Analysis
      • Data Analysis and Visualization
      • Financial Data Tools
      • Python
      • SQL
    • Credit
      • Credit Analysis
      • Restructuring
    • Financial Literacy Essentials
      • Financial Data Tools
      • Financial Math
      • Foundations of Accounting
    • Industry Specific
      • Banks
      • Chemicals
      • Consumer
      • ESG
      • Insurance
      • Oil and Gas
      • Pharmaceuticals
      • Project Finance
      • Real Estate
      • Renewable Energy
      • Technology
      • Telecoms
    • Introductory Courses
    • Investment Banking
      • Accounting
      • Financial Modeling
      • M&A and Divestitures
      • Private Debt
      • Private Equity
      • Valuation
      • Venture Capital
    • Markets
      • Economics
      • Equity Markets and Derivatives
      • Fixed Income and Derivatives
      • Introduction to Markets
      • Options and Structured Products
      • Other Capital Markets
      • Securities Services
    • Microsoft Office
      • Excel
      • PowerPoint
      • Word & Outlook
    • Professional Skills
      • Career Development
      • Expert Interviews
      • Interview Skills
    • Risk Management
    • Transaction Banking
    • Felix Live
  • Pathways
    • Investment Banking
    • Asset Management
    • Equity Research
    • Sales and Trading
    • Commercial Banking
    • Engineering
    • Operations
    • Private Equity
    • Credit Analysis
    • Restructuring
    • Venture Capital
    • CFA Institute
  • Certified Courses
Felix
  • Data
    • Company Analytics
    • My Filing Annotations
    • Market & Industry Data
    • United States
    • Relative Valuation
    • Discount Rate
    • Building Forecasts
    • Capital Structure Analysis
    • Europe
    • Relative Valuation
    • Discount Rate
    • Building Forecasts
    • Capital Structure Analysis
  • Models
  • Account
    • Edit my profile
    • My List
    • Restart Homepage Tour
    • Restart Company Analytics Tour
    • Restart Filings Tour
  • Log in
  • Ask An Instructor
    • Email Our Experts
    • Felix User Guide
    • Contact Support

User Defined Functions, Events and Arrays

An overview of user-defined functions in Excel VBA.

Unlock Your Certificate   
 
0% Complete

8 Lessons (40m)

Show lesson playlist
  • Description & Objectives

  • 1. Introduction to User Defined Functions

    01:30
  • 2. User Defined Functions Part 1 Workout

    03:53
  • 3. User Defined Functions Part 2 Workout

    12:37
  • 4. Workbook and Worksheet Events

    02:12
  • 5. Worksheet Events Workout

    04:07
  • 6. Workbook Events Workout

    03:44
  • 7. Arrays

    01:11
  • 8. Arrays Workout

    10:28

Prev: Variables and Looping Procedure Next: Modifying the User Interface

User Defined Functions Part 2 Workout

  • Notes
  • Questions
  • Transcript
  • 12:37

A workout to demonstrate building a user-defined function along with how to write help on the function and its arguments.

Downloads

User Defined Functions Part 2 Workout EmptyUser Defined Functions Part 2 Workout Full

Glossary

Excel modeling
Back to top
Financial Edge Training

© Financial Edge Training 2025

Topics
Introduction to Finance Accounting Financial Modeling Valuation M&A and Divestitures Private Equity
Venture Capital Project Finance Credit Analysis Transaction Banking Restructuring Capital Markets
Asset Management Risk Management Economics Data Science and System
Request New Content
System Account User Guide Privacy Policy Terms & Conditions Log in
Transcript

In this workout, we are required to create a function that can perform some average and median operations on an input range.

Let's go into the Visual Basic editor and create our function.

We're going to write our function in a module, so we should insert a module.

We have two things to do in our code.

The first is to set up the function and the second is to write the select case code.

A function procedure starts with the word function and the parameters required by the functions arguments.

In this case, we will call our function multistat.

Let's declare the first variable.

The RNG or range parameter will be a range type as the function will require a range to be input as its first argument.

The op parameter is of string type as the function will require the name of the desired operation.

In the second argument, we want the output of our function to be of double data type.

It can take any number, including integers and decimals.

Note now these variables have been stated within the function.

We do not need to write DIM to declare the variables.

Again, following the function format, we now need to write the instructions given each of the select cases of our variable op, the operator, so we write select case on our op parameter.

Select case can be used to assign different instructions to each possible option of our op parameter Where the case is sum.

We are writing in sum in our op parameter.

What do we want to do? We want Excel to perform the sum function where we want the sum function performed.

We need to write worksheet function, sum in Excel VBA, so that Excel will use the sum function.

And we want to sum our first argument, the range parameter, and that was Rng.

In the next case, should we have the word average inserted into our op argument.

We want Excel to go ahead and calculate the average of the chosen range.

So in the case of average, what we want, we want multi stat to calculate the average of our input range.

Our input range is the first parameter in the argument, RNG Our range parameter.

The final case will be where we input median into our op argument.

So in the case of median being entered, what do we want to do? Well, the instructions here should be that multiStat equals worksheet function.

Do median and it's the median of our range parameter here.

Remember that input parameter is the RNG range object, and it is the median of that first range object R range parameter.

That is all of our cases covered and we can end the select.

Let's go back into Excel and test.

This works back in the front end of Excel.

Let's use our multistat function equals multistat.

Here's our range.

The second argument is our operator.

This was of string type and we need to type the name of our desired operation this time average, and we get the average of all of those numbers.

Finally, let's try multistat with the median stated as our desired operator In that second argument, the first argument is our desired range, the RNG parameter.

The second argument, that's our desired operation.

We want to go with median and we get the median of all of those figures.

We are now required to write a procedure to display the function information for our new multistat procedure.

Let's go ahead and do that back into Excel Visual Basic, and we're going to go back to the Visual Basic editor.

We can make our function look like an inbuilt Excel function by providing specific function information and also including it within the appropriate function category.

The code that we're going to write only has to be executed once for Excel to store this new function.

Information. We're going to use the macro options method to display a user-defined function in a built-in category within the function dialogue box.

So let's write a new sub procedure and let's call our sub procedure multistat.

Describe, and we're going to use the macro options method, so application Macro options.

The macro, well that will be equal to our multita function.

The description argument.

How do we want our new function to be described? Well, our new function performs the chosen statistical operation on a chosen range.

Next, what category do we want our new function to feature in? We want to feature in category 4.

Category 4 is the statistical category.

Here you can see all of the different categories so that we can ensure our function appears in the appropriate category onto the next argument.

And that's the argument descriptions.

This is where we'll have a description of each of the required arguments to our function.

What cues do we want to give when our users use this function tool? Argument descriptions will equal the array.

Our first argument we want to describe as the chosen range of cells, and our second argument, the name of the operator.

That is all of our arguments completed.

We can run this macro once and then let's test out our new function in a spare cell.

I'm going to input the name of our decide operation here.

Let's choose some, and I'm going to start writing the name of our function multistat.

And we can have some help on multistat here we're told that multistat performs a chosen statistical operation on a chosen range, and our range argument is the chosen range of cells.

Well, let's choose those.

The next argument, well, the next argument is the name of our operator.

I'm going to choose some once I press.

Okay, we can see that familiar number of 122, the sum of all of those numbers in the range.

Content Requests and Questions

You are trying to access premium learning content.

Discover our full catalogue and purchase a course Access all courses with our premium plans or log in to your account
Help

You need an account to contact support.

Create a free account or log in to an existing one

Sorry, you don't have access to that yet!

You are trying to access premium learning content.

Discover our full catalogue and purchase a course Access all courses with our premium plans or log in to your account

You have reached the limit of annotations (10) under our premium subscription. Upgrade to unlock unlimited annotations.

Find out more about our premium plan

You are trying to access content that requires a free account. Sign up or login in seconds!

Create a free account or log in to an existing one

You are trying to access content that requires a premium plan.

Find out more about our premium plan or log in to your account

Only US listed companies are available under our Free and Boost plans. Upgrade to Pro to access over 7,000 global companies across the US, UK, Canada, France, Italy, Germany, Hong Kong and more.

Find out more about our premium plan or log in to your account

A pro account is required for the Excel Add In

Find out more about our premium plan

Congratulations on completing

This field is hidden when viewing the form
Name(Required)
This field is hidden when viewing the form
Rate this course out of 5, where 5 is excellent and 1 is terrible.
Were the stated learning objectives met?(Required)
Were the stated prerequisite requirements appropriate and sufficient?(Required)
Were the program materials, including the qualified assessment, relevant and did they contribute to the achievement of the learning objectives?(Required)
Was the time allotted to the learning activity appropriate?(Required)
Are you happy for us to use your feedback and details in future marketing?(Required)

Thank you for already submitting feedback for this course.

CPE

What is CPE?

CPE stands for Continuing Professional Education, by completing learning activities you earn CPE credits to retain your professional credentials. CPE is required for Certified Public Accountants (CPAs). Financial Edge Training is registered with the National Association of State Boards of Accountancy (NASBA) as a sponsor of continuing professional education on the National Registry of CPE Sponsors.

What are CPE credits?

For self study programs, 1 CPE credit is awarded for every 50 minutes of elearning content, this includes videos, workouts, tryouts, and exams.

CPE Exams

You must complete the CPE exam within 1 year of accessing a related playlist or course to earn CPE credits. To see how long you have left to complete a CPE exam, hover over the locked CPE credits button.

What if I'm not collecting CPE credits?

CPE exams do not count towards your FE certification. You do not need to complete the CPE exam if you are not collecting CPE credits, but you might find it useful for your own revision.


Further Help
  • Felix How to Guide walks you through the key functions and tools of the learning platform.
  • Playlists & Tryouts: Playlists are a collection of videos that teach you a specific skill and are tested with a tryout at the end. A tryout is a quiz that tests your knowledge and understanding of what you have just learned.
  • Exam: If you are collecting CPE points you must pass the relevant CPE exam within 1 year to receive credits.
  • Glossary: A glossary can be found below each video and provides definitions and explanations for terms and concepts. They are organized alphabetically to make it easy for you to find the term you need.
  • Search function: Use the Felix search function on the homepage to find content related to what you want to learn. Find related video content, lessons, and questions people have asked on the topic.
  • Closed Captions & Transcript: Closed captions and transcripts are available on videos. The video transcript can be found next to the closed captions in the video player. The transcript feature allows you to read the transcript of the video and search for key terms within the transcript.
  • Questions: If you have questions about the course content, you will find a section called Ask a Question underneath each video where you can submit questions to our expert instructor team.