VBA & macros
Automate repeat work with macros and VBA code.
- VBA AutoFilter: How to Filter Cells and Rows in ExcelIn Excel VBA, use the AutoFilter method on a range that includes the header row to filter records by a column’s value.…
- VBA AutoFilter Off: Remove Arrows or Clear FiltersTo show every row while keeping the filter controls, use VBA’s ShowAllData method when the worksheet is filtered. To remove worksheet AutoFilter…
- VBA Assign Range to a Variable: Examples and TipsTo assign an Excel range to a VBA variable, declare the variable as a Range and use Set: Dim rng As Range,…
- VBA Assign String to Variable: Syntax and ExamplesTo assign text to a VBA variable, declare it as a string with Dim and use the equals sign: message = "Hello".…
- VBA Assign Range: Set, Select, and Reference CellsTo assign a cell range to a VBA variable, declare the variable as a Range and use Set, for example: Set rng…
- VBA Array Notation: Syntax, Bounds, and ExamplesIn VBA, declare an array with parentheses after its name, such as Dim scores(1 To 5) As Long, and refer to an…
- VBA Array of Numbers: How to Declare and Work With OneIn VBA, an array of numbers stores multiple numeric values under one variable name; declare one with a numeric type, such as…
- VBA Array Function: Syntax, Examples, and GotchasIn VBA, the Array function creates an array of values and returns it inside a Variant. Assign the result to a Variant…
- VBA Array Command: Syntax, Examples, and Practical UsesIn VBA, the “array command” most people mean is the Array function: it creates an array of values, which you can store…
- VBA Array Duplicate Values: Find, Count, and RemoveYes. VBA arrays can contain duplicate values; VBA does not automatically prevent or remove them. To find repeats, compare elements or track…
- VBA Array Cells: Read and Write Ranges EfficientlyIn Excel VBA, you can read a block of worksheet cells into a Variant array with one assignment, process the values in…
- VBA Apply AutoFilter: Examples and Common FixesTo apply an AutoFilter with VBA in Excel for Microsoft 365 on Windows, call the AutoFilter method on the range that includes…
- Advanced VBA UserForms: Design, Events, and DataAn advanced VBA UserForm is a custom Excel dialog that goes beyond collecting a few values: it can validate input, load and…
- VBA Add Leading Zeros to a String Without Losing TextIn VBA, add leading zeros to a string by placing the required number of zeros before its existing characters. For a reusable…
- VBA Add Border to a Range: Code, Styles, and FixesTo add borders to a range in Excel VBA, set the range’s Borders properties. For example, Range("B2:F10").Borders.LineStyle = xlContinuous applies solid borders;…
- VBA Access: Sort Records in Queries and FormsTo sort records with Access VBA, put an ORDER BY clause in the SQL used to open a query or recordset; for…
- VBA Activate Workbook: Methods, Examples, and FixesTo activate an open workbook in Excel VBA, retrieve it from the Workbooks collection by its exact name and call its Activate…
- VBA Access: Import CSV Files ReliablyTo import a CSV file into Microsoft Access with VBA, call DoCmd.TransferText using the acImportDelim transfer type, the destination table, the file…
- VBA Access Arrays: Declare, Loop, and Resize ThemIn Microsoft Access VBA, an array is a variable that holds multiple values of the same declared type, or—when declared as a…
- UserForm VBA Properties: What They Do and How to Set ThemUserForm VBA properties control a form’s identity, appearance, size, position, and behavior in an Excel desktop workbook. You can edit many of…
- UserForm VBA Controls: Types, Events, and ExamplesUserForm VBA controls are the buttons, text boxes, lists, labels, and other interface elements you place on a VBA UserForm to collect…
- VBA UserForm: How to Show It in ExcelTo show a VBA UserForm in Excel, call its name followed by .Show, such as UserForm1.Show. Add vbModeless when users should be…
- VBA Sort Reference Is Not Valid: Causes and Fixes“The sort reference is not valid” is an Excel sorting error, not a VBA syntax rule. In a macro, it usually means…
- Excel VBA Project Missing? Causes, Checks, and RecoveryIf an Excel workbook was saved as .xlsx, its VBA project was removed because that file format cannot store VBA macros. If…
- Unload UserForm VBA: Close Forms and Reset State SafelyIn VBA, use Unload UserForm1 to close and unload a form, or use Unload Me from code inside that form. Unloading removes…
- VBA For Loop Syntax: Examples and Common VariationsIn VBA, a For...Next loop repeats code for a counter that moves from a starting value to an ending value: write For…
- Set Workbook and Worksheet in VBA: How It WorksIn Excel VBA, use Set to assign a workbook or worksheet object to a variable, then refer to that variable in your…
- Sending Emails With VBA: Excel and Outlook GuideYes—Excel VBA can create and send email through classic Outlook for Windows. In Excel, add a macro that creates an Outlook mail…
- Refresh Worksheet VBA: Methods, Examples, and FixesTo recalculate formulas on one worksheet with VBA, call that worksheet’s Calculate method. To refresh imported data, use ThisWorkbook.RefreshAll—but that refreshes workbook…
- Reset UserForm VBA: Clear Controls and Restore DefaultsIn Excel VBA, reset a UserForm by setting its input controls back to blank or to chosen defaults. For a fresh form…