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

Variables and Looping Procedure

An introduction to variables and looping procedure, the building blocks of effective and efficient Excel VBA coding. Walk through building looping procedures and their application to automating tasks in Excel.

Unlock Your Certificate   
 
0% Complete

13 Lessons (55m)

Show lesson playlist
  • Description & Objectives

  • 1. Introduction to Variables

    02:39
  • 2. Declaring Variables

    02:37
  • 3. Declaring Variables Workout

    07:18
  • 4. For Each Next

    02:03
  • 5. For Each Next Workout

    05:31
  • 6. If Then Else

    02:28
  • 7. If Then Else Workout

    07:13
  • 8. For Next

    02:31
  • 9. Do Loops

    03:43
  • 10. Select Case

    02:11
  • 11. Select Case Workout

    12:57
  • 12. With End With

    01:14
  • 13. Error Handling

    02:06

Prev: Objects, Properties and Methods Next: User Defined Functions, Events and Arrays

Select Case Workout

  • Notes
  • Questions
  • Transcript
  • 12:57

Use the Select Case.

Downloads

Select Case Workout EmptySelect Case 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 use select case to write VBA code to calculate the fee associated with each deal.

The deal fees are 4% for deal values, up to $1 billion, 6% for deal values between 1 billion and $10 billion and 8% for deal values.

Above $10 billion.

We're told to select cell C 10 as the active cell in the front end of Excel and then write looping procedure to work through each subsequent cell until we reach an empty cell In column C.

Cell C 10 is selected.

Let's now go into the Visual basic editor to write our code.

The first thing that we need to do is to write, sub and give our sub procedure a name.

I'll call this one workout 4.

We have two things to do in our code.

The first is to write to looping procedure to iterate through the deal value cells.

The second is to write select case procedure so that the appropriate fee value is chosen.

Based on the deal value provided, we need two variables.

The first will hold the deal value, those values provided to us in column C of the spreadsheet, and the second will hold the deal fee that is assigned based on the rules given in the workout.

The first variable that we will declare will be called deal value and we will assign this as a double data type.

Double is used as it provides us with most flexibility.

Large numbers including decimals, are able to be handled by the double data type.

The second variable that we will declare, we'll call deal fee.

Again, let's declare this variable as a double.

That means that it can handle any number including decimals.

This will provide us with the most flexibility.

Next, let's write a loop to cycle through all the cells from the active cell down to the end of the list.

In column C, a do loop will offer more flexibility as we, we can manage a list of any size.

If we use a do loop, we can do until the value in the list is blank.

Let's begin. Our do loop.

We do until the active cell in the front end of Excel and its value.

Property is equal to nothing, is equal to blank and we state the blank by showing a double quotation mark.

Next, let's write the select case code.

Inside our do loop, the deal value variable needs to be assigned a value and that value will be the value of the active cell in our Excel spreadsheet.

Inside the loop we indent our code.

The deal value variable is assigned the value of the active cell, active cell and its value property.

Next, let's construct the select case.

We always start with the words select case and then the expression we wish to assess.

Here we want to assess the deal value variable select case and deal value.

You notice once we press enter, as long as I've spelled the value, the variable of deal value correctly, it will capitalize as appropriate.

We then state the condition note.

We must always start this with the word case. For cases of between zero and one where the deal value is between zero and $1 million.

Then what instruction should we provide given that this is true, well deal fee should be 4%.

The deal fee variable will take a value equivalent to naught point naught four or 4%.

Let's state our next condition, again using case for cases between one to 10 where we are assessing our deal value.

The instruction should be that the deal fee is equivalent to 0.06 or 6%.

Let's set our final condition where the case is greater than 10.

Where we are assessing our deal fee value rather our deal value, the deal fee is set to 8% or naught point naught eight.

That is the end of all of our conditions and we can end our select case with the words end select the sell in column D needs the fee value inserted and the fee value equal to rather the deal fee multiplied by the deal value.

We can write this code to put this in the cell directly to the right of our active cell.

Let's do that.

Our active cell, we started with cell C 10 and let's use the offset property and we want to offset by zero rows and one column ie, We're going one column to the right into column D.

The value property of that cell will be equal to the deal value multiplied by the deal fee of that cell.

After we've carried out that instruction, we want to move the active cell down by one and then select this cell.

To do this, we use the offset property once again and the select method.

We move the active cell down by one row.

We move across by zero columns and specify the select method.

Select being an action.

Finally, of course, we need The the syntax to close the loop to close our do until loop, we write the word loop.

That is our code written.

Let's now step through this procedure and look at how it executes.

If we step into our procedure using F 8, we can see as each line of the code is executed, the first thing that happens is that the deal value is assessed using select case, we can see for deal A that it is the case that deal A has a value over 10 and the deal fee variable will be assigned the value of naught point naught eight.

Executing this next line of code, we say that the active cell here sell C 10.

We offset one column to the right and the value of that sell sell D 10 will be given the value of the deal value multiplied by the deal fee.

After we have conducted that line of code, we offset one row down and we loop back to the top of the procedure.

Let's step through again here.

The deal value is less than one.

It's the case that it is between zero and one and the deal fee variable will be assigned to be naught point naught four.

The active sell offs sell offset one column to the right.

Its value is equal to the deal value of naught point of naught 0.5 multiplied by the deal fee of naught point four.

Let's loop through the procedure again here for deal C, it is the case that in deal C, the value is between one and 10, so the deal fee variable is assigned the value of naught point naught six.

The cell offset one to the right of the current active cell is assigned the value of the deal value 2.4 multiplied by the deal fee of 0.6.

The final line of our instruction procedure tells us to go from the active cell and offset one row down.

This time it is the case that the deal value is greater than 10 and so the deal fee variable will take the value of naught point naught eight.

The cell, one cell to the right of our active cell is assigned the value of the deal value of 12 multiplied by the deal fee of naught point naught Eight. We offset by one more row to make our active cell C 14 and we assess the value of cell C 14, our active cell if that cell is between one and 10, as is the case here, well, the deal fee variable takes the value of naught point naught six offsetting one cell to the right of the active cell.

The value property of that cell is assigned to take the value of the deal value 3.6 multiplied by the deal fee assigned of naught point naught six.

To give naught.22.

We have no more cells to loop through as we've reached the case where the active cell is blank.

Our sub procedure ends and we have completed our workout.

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.