From the course: Excel: Learning VBA
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Define static variables and constants - Microsoft Excel Tutorial
From the course: Excel: Learning VBA
Define static variables and constants
- [Instructor] Normally when you create a variable within a subroutine, it only retains its value while the subroutine is running. The next time you run it, every variable's value resets to zero for numbers and a zero length string for strings and so on. However, there are two ways you can create variables that hold their values. They are by defining constants and by defining static variables. In this movie, I will show you how to do both. My sample file is 02_04_Constants, and you can find it in the "Chapter Two" folder of the "Exercise Files" collection. In this workbook's worksheet, I have a list of sales for a particular day, and it is important that one of the cells with a numerical value is selected because the code that we use will work on the active cell. So, I've clicked before, you can click any of the others in that column that have a number but you might see a different result. In fact, I know you will. Now…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Introduce Excel VBA data types4m 5s
-
(Locked)
Declare variables and require declaration before use5m 27s
-
(Locked)
Manage variable scope3m 50s
-
(Locked)
Define static variables and constants5m 42s
-
Create a calculation using mathematical operators5m 10s
-
(Locked)
Define arrays7m 10s
-
Define and use object variables3m 3s
-
(Locked)
Streamline code references using With…End With statements4m 40s
-
(Locked)
Challenge: Define variables, constants, and calculations2m 5s
-
(Locked)
Solution: Define variables, constants, and calculations3m 13s
-
(Locked)
-
-
-
-
-
-