VBA & macros
Automate repeat work with macros and VBA code.
- VBA Sort Data: Methods, Examples, and Common FixesIn Excel VBA, sort data with the worksheet’s Sort object: define the range, add one or more sort keys, set whether the…
- VBA Sort Column Ascending in ExcelTo sort a column in ascending order with VBA, use Excel’s Range.Sort method and set Order1:=xlAscending. For example, sort A2:A100 with Range("A2:A100").Sort…
- VBA Sort Data in Excel: How to Build a Reliable MacroYes. In Excel for Microsoft 365 on Windows, VBA can sort a range or table by one or more columns using Excel’s…
- VBA Sort a Column Alphabetically in Excel with MacrosIn Excel VBA, sort alphabetically by calling Range.Sort with the range to sort, a key cell in the column, Order1:=xlAscending, and the…
- VBA Sort Collection: Methods and Practical ExamplesVBA’s Collection object has no built-in sort method. To sort a collection, copy its items into an array, sort that array, and…
- VBA Sort Column: Code, Options, and Common FixesTo sort a column with VBA in Excel, define the sort key and apply a sort to the full data range: use…
- VBA Sort.Apply: How to Configure and Run Excel SortsSort.Apply is the VBA method that runs a sort after you have configured its range, sort keys, and options. In Excel for…
- VBA Sort Cells in Excel: Code, Options, and Common FixesTo sort cells with VBA in Excel, sort the entire data range by a key column—not just one column if the rows…
- VBA Show UserForm: Open a Form in ExcelTo show an Excel VBA UserForm, call its Show method, usually from a standard module: UserForm1.Show. In Excel for Microsoft 365 on…
- VBA SortFields.Add2: What It Does and How to Use ItSortFields.Add2 is an Excel VBA method that adds a sort key to a sort operation. It works much like SortFields.Add, but its…
- VBA Pivot Tables: Create, Refresh, and Set Fields EasilyYes. In Excel for Microsoft 365 on Windows, VBA can create a PivotTable, assign its row, column, filter, and value fields, and…
- VBA Set AutoFilter Range: Setup, Examples and FixesTo set an AutoFilter range in Excel VBA, identify a rectangular range that includes the header row, then call its AutoFilter method—for…
- VBA: Send Multiple Pictures in Outlook Email with ExcelYes. In Excel for Microsoft 365 on Windows, VBA can create an Outlook email and add several picture files as attachments; it…
- VBA Send Email With Attachments From a Folder in ExcelTo send an Outlook email with every file in a folder attached, run an Excel VBA macro that loops through the folder’s…
- VBA Send Mail from Excel: Outlook Setup and Code GuideYes. In Excel for Microsoft 365 on Windows, VBA can create and send an email through classic Outlook using Outlook’s object model.…
- VBA Send Email to Multiple RecipientsYes. In Excel VBA on Windows, you can create an Outlook email and add several addresses to its Recipients collection, or place…
- VBA Send Email From a Shared Mailbox in OutlookYes. In classic Outlook for Windows, VBA can create a message and set its SentOnBehalfOfName property to the shared mailbox address before…
- VBA Select Pivot Table: Safe Methods and ExamplesTo select an entire PivotTable with VBA, use its TableRange2 property and call Select: Worksheets("Report").PivotTables("PivotTable1").TableRange2.Select. The worksheet must be active before a…
- VBA Scripting.Dictionary: How It Works and When to Use ItA VBA Scripting.Dictionary is an object that stores pairs of unique keys and associated values, letting a macro look up, count, or…
- VBA Return Dictionary From Function: Setup and ExamplesYes. In VBA, a function can return a Scripting.Dictionary object; assign the dictionary to the function name with Set, then use Set…
- VBA Scripting.Dictionary: How It Works and How to Use ItA VBA Scripting.Dictionary stores data as unique keys paired with values, so code can look up an item by name or ID…
- VBA Resize UserForm: Set Size and Enable ResizingTo resize an Excel VBA UserForm, set its Width and Height properties in the form’s Properties window or in the form’s Initialize…
- VBA Reset AutoFilter: Clear Filters, Keep the SetupTo reset an Excel AutoFilter in VBA while keeping its dropdown arrows, clear the active filter rather than turning AutoFilter off: use…
- VBA Rename UserForm: Steps, Code, and Common IssuesTo rename a VBA UserForm in Excel for Microsoft 365 on Windows, open the Visual Basic Editor, select the form in Project…
- VBA Remove Item From Dictionary: Methods and ExamplesTo remove one entry from a VBA dictionary, call dict.Remove key, where key is the entry’s key—not its stored value or position.…
- Excel Mac VBA: What Works and How to Use ItYes—Microsoft Excel for Mac supports VBA, so you can create, edit, and run many Excel macros on a Mac. The main caveat…
- VBA Remove AutoFilter: Clear Filters or Remove ArrowsTo clear the active filters on a worksheet but keep its dropdown arrows, use If ws.FilterMode Then ws.ShowAllData. To remove a worksheet…
- VBA Quit UserForm: How to Hide or Unload the FormTo quit a VBA UserForm, use Unload Me in a button or event procedure on the form; this closes the form and…
- VBA UserForm References: How to Show and Control FormsIn Excel VBA, reference a UserForm by its form class name, such as UserForm1, or create an explicit object variable with New…
- VBA Print Variable in a MsgBox: Syntax and ExamplesTo display a VBA variable in a message box, use MsgBox variableName, or combine a label and the value with MsgBox "Value:…