Variables and Constants in Excel Visual Basic
Part two of an eight-part series of blogs

This blog explains the nuts and bolts of Excel VBA variables, including how to declare them, how to set their scope and all sorts of other tips and tricks. The blog also covers constants in Excel macros.

  1. Variables in Excel Visual Basic macros
  2. What is a Variable? VBA macro variables. (this blog)
  3. Declaring Variables in Visual Basic for Applications
  4. Using Variables (Assigning and Retrieving Values)
  5. Forcing Declaration of Variables (Option Explicit)
  6. Useful Things to Know about Variables
  7. The Scope of Variables
  8. Constants in Excel Visual Basic for Applications

This blog is part of our Excel macros online tutorial series.  Alternatively, we run training courses in the UK in Excel and also in Visual Basic for Applications (and are always looking for partners in the US or other English-language countries!).

Posted by Andy Brown on 05 September 2011

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

What is a Variable?

In the example shown in part one of this blog, we want to store the name of our superhero and the rating applied to them somewhere on your computer which is easy to access and use.  That somewhere is called a variable.

Variables are (a bit) like suitcases

A variable is a bit like a suitcase, in that it stores something.  But there are two big differences: suitcases don't (usually) have names, and they're not restricted to storing just one thing.  So if you're the sort of person who names their suitcases and stores just one thing in each, you'll find variables strangely familiar!

Suitcase holding superhero name

Our variable to hold the superhero name.

Suitcase to hold rating varaible

The variable to hold the rating.


So know we know what variables are (!) - how to create them?


This blog has 0 threads Add post