Skip to content
- Excel VBA Create Dictionary: Setup, Code, and Practical TipsTo create a Dictionary in Excel VBA on Windows, declare an object and set it to CreateObject("Scripting.Dictionary"). You can then add unique…VBA & macros
- Excel VBA: Create and Use an Array of StringsIn Excel VBA, declare a string array with Dim names() As String, give it a size with ReDim names(0 To 2), then…VBA & macros
- Excel VBA: Count Occurrences in a StringTo count how many times one piece of text appears in another in Excel VBA, search repeatedly with InStr, advancing past each…VBA & macros
- Excel VBA: Convert a Variant to a StringIn Excel VBA, use CStr to convert a Variant value to a String: for example, textValue = CStr(value). Check first for special…VBA & macros
- Excel VBA Connection Strings: Providers and ExamplesExcel VBA does not have one universal connection-string provider: choose a provider that matches the data source and is installed on the…VBA & macros
- Excel VBA Concatenate Strings: Methods and ExamplesIn Excel VBA, concatenate strings with the ampersand operator (&), which joins text values into one string. For example, firstName & "…VBA & macros
- Excel VBA Comment Function: What It Does and How to Use ItExcel VBA has no single “comment function”: use an apostrophe (or Rem) to add a non-running comment to VBA code, and use…VBA & macros
- Excel VBA Code to Send an Email With an AttachmentTo send an email with an attachment from Excel on Windows, use VBA to create a message through classic Outlook, add the…VBA & macros
- Excel VBA Code to Sort Data by One or More Columns in ExcelTo sort data with Excel VBA, set the range to sort, add one or more sort keys, specify whether the first row…VBA & macros
- Excel VBA: Loop Through Cells in a RangeTo loop through every cell in an Excel range with VBA, use a For Each loop and a Range variable: For Each…VBA & macros
- Excel VBA Clear Dictionary: Methods, Examples, and TipsTo empty a VBA Scripting.Dictionary, call its RemoveAll method: dict.RemoveAll. This removes every key and item while leaving the dictionary object available…VBA & macros
- Excel VBA Clear Array Contents: ReDim, Erase, and MoreIn Excel VBA, use Erase arrayName to clear an array: it deallocates a dynamic array, but resets a fixed-size array’s elements to…VBA & macros
- Excel VBA Checkbox Loop: How to Read Every CheckboxTo loop through worksheet checkboxes in Excel VBA, use the worksheet’s CheckBoxes collection for Forms controls or its OLEObjects collection for ActiveX…VBA & macros
- Excel VBA: How to Center a Range HorizontallyTo center the contents of every cell in an Excel range horizontally with VBA, set the range’s HorizontalAlignment property to xlCenter. For…VBA & macros
- Excel VBA: Change a PivotTable Data SourceTo change an Excel PivotTable’s source with VBA, create a new PivotCache from the replacement range, assign it with PivotTable.ChangePivotCache, then refresh…VBA & macros
- Excel VBA: How to Cancel a UserFormTo cancel an Excel VBA UserForm, handle a Cancel button by setting a cancellation flag and hiding the form; handle the title-bar…VBA & macros
- Excel VBA: How to Cancel a LoopTo cancel a running Excel VBA loop on Windows, press Ctrl+Break; Esc may also work, especially when the code calls DoEvents. For…VBA & macros
- Excel VBA Calendar Date Picker: Options and SetupExcel for Microsoft 365 on Windows does not include a universal VBA calendar date-picker control that you can simply add to any…VBA & macros
- Excel VBA Bubble Sort for Arrays: Code and ExplanationTo bubble-sort a one-dimensional VBA array, compare neighboring items and swap them when they are out of order; repeat until a full…VBA & macros
- Excel VBA Bubble Sort: Code, Steps, and AlternativesExcel VBA can sort a selected, single-column range of numbers with a bubble-sort macro: the code below repeatedly compares neighboring values and…VBA & macros
- Excel VBA: How to Break Out of an Endless LoopTo stop a running Excel VBA loop on Windows, press Ctrl+Break (or Ctrl+Pause on keyboards with that key), then choose End to…VBA & macros
- Excel VBA: Stop an Endless Loop and Recover SafelyTo stop a running Excel VBA loop on Windows, press Ctrl+Break (on some keyboards, use Ctrl+Fn+Pause), then choose End or Debug in…VBA & macros
- Excel VBA Binary Strings: Text, Bytes, and BitsIn Excel VBA, a String is text, not a raw sequence of binary bytes. If you mean a string of 0s and…VBA & macros
- Excel VBA Average Function: Syntax, Examples, and TipsIn Excel VBA, calculate an average by calling Excel’s built-in function: use Application.WorksheetFunction.Average(range) when you want a numeric result, or Application.Average(range) when…VBA & macros
- Excel VBA AutoFilter: Select Visible Cells SafelyIn Excel VBA, use SpecialCells(xlCellTypeVisible) on the filtered data range to get cells left visible by AutoFilter. Exclude the header from that…VBA & macros
- Excel VBA AutoFilter Tables: Setup, Code, and Common FixesTo filter an Excel table with VBA, use the table’s Range.AutoFilter method and specify the column’s position within the table and the…VBA & macros
- Excel VBA AutoFilter Syntax: Fields, Criteria, and ExamplesIn Excel VBA, call AutoFilter on a range that includes the list’s header row; the usual syntax uses the named arguments Field,…VBA & macros
- Excel VBA AutoFilter: Filter Rows by a Specific ValueTo filter a range by one exact value with Excel VBA, call AutoFilter on the range that includes the headers and set…VBA & macros
- Excel VBA AutoFilter Sort: Filter and Sort Data RowsTo filter and sort rows with Excel VBA, apply AutoFilter to the data range, then configure that range’s Sort object. For example,…VBA & macros
- Excel VBA AutoFilter Operator ExplainedIn Excel VBA, the AutoFilter Operator argument tells Excel how to apply filter criteria: use xlAnd or xlOr to combine two conditions…VBA & macros