VBA Lesson 19: VBA for Excel Variables
This is an excerpt from Pierre Leclerc (www.excel-vba.com)
You will start developing complex and sophisticated programs in Excel and you will start working with very large sets of data when you discover the variables.
A variable is an object that you create and in which you can store text, dates, numbers or almost anything else. Why should you use variable? The first good reason is to make your code dynamic, to avoid hard coding some values.
Hard Coding vs Dynamic Coding
You are hard coding when you write:
You are dynamically coding when you enter the name of the file in an cell (A1) of your Excel sheet and you write.
You will also create variables to count the number of rows, store the result in a variable and then do something as many time as there are rows.
For varCounter = 1 to varNbRows
In the VBA procedure above the value in each cell is multiplied by 2 then the cell below is selected. This action is repeated as many times as there are rows in the set of data.
Go to the next lesson