From the course: Excel: Learning VBA

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Define static variables and constants

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…

Contents