

When you use this statement, you will not be able to run your code if it contains undeclared variable types. To force yourself to declare all variables you use, add the following statement to the top of your VBA module (outside all sub routines): If you let VBA handle data types, you’ll be sacrificing speed and memory. If you don’t set variable types, VBA will use the default data type: Variant. It’s good practice to declare the types of your variables in Excel because your code will run faster and use memory more efficiently. ThemeFont = xlThemeFontMinor End WithĪnd here is what the entire macro looks like after deleting unrelated code: Sub recorder_example() Range("A1").Select ActiveCell.Formula = "John Doe" Range("A2").Select ActiveCell.Formula = "=NOW()" Range("A1:A2").Select = True = 22 Selection.HorizontalAlignment = xlCenter End Sub Here is the code generated to change the font size to point 22: With Selection.Font. The Macro Recorder can be excessive, and it would be a good idea to simplify this macro by deleting irrelevant code. For example, although you changed the font size to point 22, Excel created code that set many other font-related properties.

You may be surprised by the amount of code that’s generated by simple commands from the Macro Recorder. Once you’ve recorded your macro, you can view the code that you generated: Choose Developer tab ->Code sub-tab -> Macros -> Select your macro name -> Step Into
