Join Curt Frye for an in-depth discussion in this video Defining static variables and constants, part of Learning VBA in Excel.
Normally, when you create a variable within a subroutine, it only retains its…value while the subroutine is running.…The next time you run the subroutine every variable's value resets to zero for…numbers, 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 Static variables and by defining Constants. As an example,…let's look at the code I have in this workbook.…When you create a variable using a Dim statement, that variables value resets to…its default value, which again is zero for numbers, every time this subroutine is called.…
So, for example, let's say that I'm using the current total in the total…delivery subroutine. If I press F5, Excel adds 20, which is the delivery charge, to…the value in the active cell, which is 382.00, and the value is $402.…The second dialog box that appeared I'll use in a moment, so don't worry…about that for now.…If our run the subroutine again by pressing F5, I still get $402. Because Excel…
- Working in the Visual Basic Editor
- Adding code to a macro
- Creating, exporting, and deleting code modules
- Declaring and using variables
- Managing variable scope
- Defining arrays
- Managing workbooks and worksheets with VBA
- Repeating tasks with loops
- Debugging VBA code
- Cutting, copying, and pasting cell data
- Running and triggering event procedures
Skill Level Advanced
Excel 2016: Power Query (Get & Transform)with Oz du Soleil1h 49m Intermediate
1. Introducing Visual Basic for Applications (VBA)
2. Defining Variables, Constants, and Calculations
3. Adding Logic to Your VBA Code
4. Debugging Your VBA Code
5. Managing Workbook Elements and Data in VBA
6. Adding Advanced Elements to Your Workbook
7. Using Excel Events in Your VBA Code
8. Putting It All Together
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.