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

Declaring Variables Workout

  • Notes
  • Questions
  • Transcript
  • 07:18

Workout to demonstrate how to declare variables in VBA code and use variables in a formula.

Downloads

Declaring Variables Workout EmptyDeclaring Variables 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 write VBA code to convert an input temperature in degrees Celsius into a temperature in degrees Fahrenheit.

We should declare a local variable named Celsius input and assign that variable a value of 20.

We are also rather required to declare a global variable named Fahrenheit Calc.

We should then display our output temperature in degrees Fahrenheit in cell B 9.

Let's go into the Visual Basic editor via the developer tab pressing visual basic.

We will write our code into a module, so we go insert module.

Now you'll notice that the words option explicit automatically appear at the start of my module.

This means that in any coding that I write, we are required to declare variables.

We can either write option explicit freehand at the top of our module, or if you go to tools, options, and check the box That's called require variable declaration.

Checking this box will automatically add the wording option explicit to the start of all of your modules, and this will mean that you have to state the variables in your code.

The first variable that we are required to declare is a public variable, and we do that by writing the word public.

Public Fahrenheit Calc, Fahrenheit Calc is the name of our variable that will take the value of the temperature in degrees Fahrenheit, and we will declare this as a double, as this variable has been declared as a public variable, it can be used and recognized by all of the sub-procedures within the module and all of the modules within our workbook.

Let's now write our sub procedure to carry out the required instructions.

As always, we begin our sub procedure with the syntax sub and we'll call our sub procedure work out one.

The first thing that we should note is a comment so that we can remind ourselves and other users of the file what the formula is to work from degrees Celsius to degrees Fahrenheit.

The formula for going from degrees Fahrenheit or rather degrees Celsius to degrees Fahrenheit is apostrophe for the comment F degrees Fahrenheit Equals 32 plus 1.8 times by the temperature in degrees Celsius.

As we've put an apostrophe in front of the code, the code turns green.

That line of code won't be executed, but it sits there as a comment for us and other users of our spreadsheet to note the formula.

The next thing that we are required to do is declare our local variable.

We use that by writing dim and the name of our local variable is Celsius input.

I'll declare this variable to take a data type of double.

It can take any number, integer or decimal that will give us the most flexibility.

The next thing that we have to do is assign our variable of Celsius inputs a value, and we're going to assign Celsius inputs a value of 20.

Next, what we need to do is we need to state our calculation of the variable Fahrenheit calc.

Fahrenheit Calc is equal to 32 plus 1.8 multiplied by our variable Celsius input.

We are assigning the value of 32 plus 1.8 times by 20 the value of Celsius input to our variable Fahrenheit calc.

Now you'll notice that I input the word Celsius input without the capitalized I.

When I press enter excel VBA recognizes the name of my variable and capitalizes it at appropriate.

This is a great way to make sure that we're spelling our variables correctly and by using a name that's sensible, we can also keep track more methodically of what those variables mean.

Next, once we've assigned a value to our variable Fahrenheit calc, we then want to put that value of the variable into cell B 9 in our spreadsheet.

We do that by stating the range object cell B 9 and its value property, and we want to assign that value property with the value of our variable Fahrenheit calc.

I input Fahrenheit calc in lowercase.

Hopefully excel VBA will capitalize this as it recognizes the name of the variable.

Our sub procedure is complete.

Let's go back into excel VBA and execute this sub procedure to see if it works.

Back in the front end of Excel, we go to developer view macros and we can see our macro workout one.

Let's run this macro, and in cell B 9 we have the 68 degrees Fahrenheit.

That is our required output.

20 degrees Celsius is equivalent to 68 degrees Fahrenheit.

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.