VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA MsgBox 3 Buttons: Options, Results, and ExamplesTo show three buttons in an Excel VBA message box, use a built-in button-set constant such as vbYesNoCancel in the MsgBox function.…
- Excel VBA Mid Function: Syntax, Examples, and TipsIn Excel VBA, the Mid function returns part of a string, starting at a position you specify. Use Mid(text, start, length) to…
- Excel VBA Month Function: Syntax, Examples, and TipsIn Excel VBA, the Month function returns the month number from a date: an integer from 1 for January through 12 for…
- Excel VBA Move Worksheet: Code and Key DetailsTo move a worksheet with Excel VBA, use the worksheet’s Move method and specify the sheet it should go before or after.…
- Excel VBA Merge Range: How to Merge Cells Safely with VBATo merge a range with Excel VBA, call the Merge method on a Range object, for example Range("B2:D2").Merge. Excel keeps the value…
- Excel VBA MAX Function: How to Find the Largest ValueExcel VBA does not have a built-in Max function, but a macro can use Excel’s worksheet function through Application.WorksheetFunction.Max or Application.Max. For…
- Excel VBA Max String Length: Limits and WorkaroundsIn Excel VBA, a variable-length String can hold roughly 2 billion characters in theory, but available memory and the way VBA represents…
- Excel VBA Maximum String Length: Limits and WorkaroundsA variable-length VBA String can hold approximately 2 billion characters in theory, but that is not a practical amount you can count…
- Excel VBA Match Date: Find Dates in a RangeTo match a date in an Excel range with VBA, use Application.Match with match type 0, which requests an exact match. For…
- Excel VBA Math Functions: What They Do and How to Use ThemExcel VBA includes built-in math functions such as Abs, Sqr, Log, Sin, and Round, which you can call directly in a macro.…
- Excel VBA Macro to Send an Email With a Table in the BodyYes. In Excel for Microsoft 365 on Windows, a VBA macro can turn a worksheet range into an HTML table and place…
- Excel VBA Array Loops: For, For Each, and ExamplesTo loop through an array in Excel VBA, use For Each when you need each value, or a For loop with LBound…
- Excel VBA Lowercase: Use LCase in Macros and FunctionsIn Excel VBA, use the built-in LCase function to convert text to lowercase; its string-returning counterpart, LCase$, is also available. For example,…
- Excel VBA Macro Recorder: How It Works and When to Use ItThe Excel VBA macro recorder turns many actions you perform in a workbook into VBA code that you can run again. In…
- Excel VBA: Loop Through Visible Rows in Filtered DataTo loop through only visible worksheet rows in Excel VBA, get a range of the data cells and use SpecialCells(xlCellTypeVisible), then process…
- Excel VBA Loop Through Used Rows: Safe, Fast MethodsTo loop through rows Excel considers used, set a range to the worksheet’s UsedRange and iterate over its rows. For a regular…
- Excel VBA: Loop Through Rows to the Last RowTo loop through data rows in Excel VBA, find the last nonempty cell in a reliable column, then use a For loop…
- Excel VBA Loop Through Rows: Practical Examples and TipsTo loop through rows in Excel VBA, set a row counter and use a For...Next loop, usually from the first data row…
- Excel VBA: Loop Through Rows in a Range EfficientlyTo loop through every row in an Excel range with VBA, use For Each rowRange In dataRange.Rows when you want to process…
- Excel VBA: Loop Through Only Visible RowsTo loop through only visible data rows in Excel VBA, apply SpecialCells(xlCellTypeVisible) to a one-column range that excludes the header, then process…
- Excel VBA Loop Through a Folder: Practical ExamplesTo loop through files in a folder with Excel VBA, use the Dir function to find a matching file, process it, and…
- Excel VBA Loop Through Columns: Practical ExamplesTo loop through columns in Excel VBA, use a For loop with a column number, or a For Each loop over a…
- Excel VBA: How to Loop Through a DictionaryTo loop through a VBA dictionary, use For Each key In dict.Keys, then retrieve each value with dict(key). A dictionary stores data…
- Excel VBA Loop Syntax: For, Do, and Each ExplainedExcel VBA loops repeat a block of code: use For...Next for a known number of repetitions, For Each...Next to visit every item…
- Excel VBA: Loop Through All Sheets in a Workbook SafelyTo loop through every worksheet in a workbook with Excel VBA, use a For Each loop over that workbook’s Worksheets collection. For…
- Excel VBA: How to Loop Through an Array of StringsIn Excel VBA, use For Each to visit every string in an array, or use a counter with LBound and UBound when…
- Excel VBA Loop Over an Array: Examples and PatternsTo loop over a VBA array in Excel, use For Each when you need to process every item, or a numbered For…
- Excel VBA Loop Over Rows: Examples and Best PracticesTo loop over rows in Excel VBA, use a For...Next loop from the first data row to the last row you want…
- Excel VBA Loop Statements: Types, Examples, and TipsAn Excel VBA loop statement repeats a block of code, either for a set number of times or while a condition is…
- Excel VBA Log Function: Syntax, Examples, and BaseIn Excel VBA, Log(number) returns the natural logarithm of a positive number—the logarithm with base e. For a different base, divide two…