Excel Agility: Macro Basics Part 2
Notice: No webinar is currently available in this series.
This webinar is not currently available, new dates coming soon.
Frequently Asked Questions
The Visual Basic for Applications (VBA) editor is where you view and modify the code generated by the Macro Recorder. Access it by pressing Alt+F11 or clicking Visual Basic on the Developer tab. The editor shows a project tree on the left listing all open workbooks and their modules—recorded macros are stored in Module1 or similar. Double-clicking a module opens the code in the right pane where you can edit it directly. Common edits include changing hard-coded cell references to variables, removing redundant steps the recorder captured, adding error handling, or inserting comments for readability. Even basic modifications—such as removing a Select statement that the recorder adds unnecessarily or changing a static range to a dynamic one—make recorded macros significantly more efficient and robust. The VBA editor also provides IntelliSense code completion and a debugger for stepping through code line by line. Comfort with the VBA editor is the next step after learning to record macros and is taught in Aurora Training Advantage's Excel Agility: Macro Basics Part 2 webinar.
Variables in VBA are named containers that store data values—numbers, text strings, dates, or objects—for use within a macro. Declaring variables with Dim at the top of a procedure (e.g., Dim lastRow As Long) makes code more readable and catches type errors during development. Using variables allows macros to work dynamically rather than with hard-coded values. For example, storing the last row of data in a variable lets a macro process all rows in a dataset regardless of how many rows exist—making it reusable for files that grow over time. Common variable types include Integer and Long for whole numbers, Double for decimals, String for text, Boolean for true/false flags, and Range or Worksheet for Excel objects. Using the Option Explicit statement at the top of a module forces all variables to be declared, preventing hard-to-find bugs caused by typos in variable names. Understanding variables is the foundational programming concept that separates basic recorded macros from flexible, professional-grade VBA automation in Excel.
Loops in VBA allow a macro to repeat a set of actions multiple times without duplicating code—essential for processing each row in a dataset, each sheet in a workbook, or each file in a folder. The most common loop types are For...Next (repeats a fixed number of times), For Each...Next (iterates over a collection like all cells in a range or all sheets in a workbook), and Do While...Loop (repeats while a condition remains true). For example, a For Each loop over all worksheets in a workbook can apply consistent formatting or extract a summary value from each sheet automatically. Combined with the technique of finding the last row dynamically—using Cells(Rows.Count,1).End(xlUp).Row—loops can process datasets of any size without modification. Loops are the single most powerful concept in VBA for automating repetitive Excel tasks and are a core topic in intermediate macro training. Aurora Training Advantage's Excel Agility: Macro Basics Part 2 covers practical loop examples applicable to real business reporting scenarios.
If-Then statements in VBA allow macros to make decisions—executing different code blocks based on whether a condition is true or false. The basic syntax is If condition Then ... Else ... End If. For example, a macro might check whether a cell value exceeds a threshold and apply different formatting based on the result. Adding ElseIf allows multiple conditions to be evaluated in sequence. If-Then statements are often combined with loops: iterating through each row and applying conditional logic to categorize or process data differently based on cell values. Nested If-Then structures handle multi-condition scenarios, while the Select Case statement offers a cleaner syntax for evaluating a single expression against multiple possible values. Understanding If-Then is essential for building macros that respond intelligently to data—such as skipping blank rows, flagging records that meet audit criteria, or routing data to different output sheets based on category values. These decision structures turn static recorded macros into dynamic, production-quality automation tools.
Assigning a macro to a button gives users a simple, visual way to run automation without navigating menus. The most common approach uses a Form Control Button: on the Developer tab, click Insert > Button (Form Control), draw it on the worksheet, and the Assign Macro dialog appears automatically—select your macro and click OK. The button can be resized, labeled with descriptive text, and positioned anywhere on the sheet. Alternatively, you can assign a macro to a shape or image by right-clicking it and selecting Assign Macro. For even faster access, macros can be added to the Quick Access Toolbar via File > Options > Quick Access Toolbar. Keyboard shortcuts can also be assigned in the Macro dialog under Options. Buttons are particularly useful in shared workbooks where you want colleagues to run reporting or formatting macros without needing to understand the underlying VBA. Clear button labels and consistent placement make macro-driven Excel files significantly more user-friendly for non-technical stakeholders.