VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Goal Seek: Automate What-If AnalysisTo run Goal Seek in Excel VBA, call the GoalSeek method on a cell containing a formula, and identify the one input…
- Excel VBA Get File Name: Workbook, Path, and FolderIn Excel VBA, use ThisWorkbook.Name for the name of the workbook containing the macro, or ActiveWorkbook.Name for the workbook currently active in…
- Excel VBA Get Username: Windows or Excel User Name?In Excel VBA on Windows, use Environ$("USERNAME") to read the current Windows account name. Use Application.UserName instead if you want the name…
- Excel VBA Global Variables: Scope and ExamplesIn Excel VBA, a global variable is a value that procedures throughout the same VBA project can access. Declare it with Public…
- Excel VBA Exit Sub: How It Works and When to Use ItIn Excel VBA, Exit Sub immediately ends the currently running Sub procedure and returns control to the code that called it, or…
- Excel VBA Format: Format Cells, Dates, and NumbersIn Excel VBA, “format” can mean either converting a value to display text with the Format function or changing how a worksheet…
- Excel VBA Enum: How It Works and When to Use ItAn Excel VBA Enum is a named set of numeric constants: it lets code use readable labels such as ExportAsPDF instead of…
- Excel VBA Evaluate: How It Works and When to Use ItIn Excel VBA, Application.Evaluate interprets a text expression using Excel’s formula language and returns the result as a Variant; for example, it…
- Excel VBA Editor: How to Open and Use ItThe Excel VBA Editor, also called the Visual Basic Editor or VBE, is the desktop window where you write, inspect, and debug…
- Excel VBA Else If: Syntax, Examples, and AlternativesIn Excel VBA, the correct keyword for a chain of conditions is ElseIf, written as one word—not Else If. Use it inside…
- Excel VBA Documentation: Where to Find the Right HelpExcel VBA documentation is available from Microsoft Learn: use the Excel object model reference for Excel-specific objects and the VBA language reference…
- Excel VBA COUNTA: Count Nonblank Cells in MacrosIn Excel VBA, count nonblank cells with Application.WorksheetFunction.CountA and pass it a range. For example, Application.WorksheetFunction.CountA(Worksheets("Data").Range("A2:A100")) returns the number of cells Excel…
- Excel VBA Dim: How to Declare VariablesIn Excel VBA, Dim declares a variable: a named place for a value your code can use, such as a row number,…
- Excel VBA Case Statement: How Select Case WorksExcel VBA does not have a separate Case statement; it uses Select Case ... End Select to choose and run one block…
- Excel VBA Code: How to Write, Run, and Troubleshoot MacrosExcel VBA code is Visual Basic for Applications instructions that automate work in the desktop version of Excel, such as formatting a…
- Excel VBA Collection: How It Works and When to Use ItAn Excel VBA Collection is an in-memory container that holds related items and lets you retrieve them by their position or, optionally,…
- Excel VBA Button: Add, Assign, and Fix Macro ButtonsAn Excel VBA button is a clickable control that runs a macro in a workbook. In Excel for Microsoft 365 on Windows,…
- Excel VBA Boolean: True, False, and How to Use ThemYes—Excel VBA has a built-in Boolean data type for values that are either True or False. Declare a variable with As Boolean,…
- Show Picture in a VBA UserFormTo show a picture in an Excel VBA UserForm, add an Image control and either set its Picture property in the designer…
- Insert an Image in a VBA UserFormTo insert an image in an Excel VBA UserForm, open the form in the Visual Basic Editor, add an Image control from…
- How to Insert a Picture in a VBA UserForm in Excel 365To insert a picture in an Excel VBA UserForm, open the Visual Basic Editor, add an Image control from the Toolbox, then…
- Excel VBA Print: How to Print Sheets and WorkbooksTo print from Excel VBA, call an object’s PrintOut method: for example, ThisWorkbook.Worksheets("Report").PrintOut sends the Report sheet to the active printer. Use…
- VBA Array Clear: How to Erase, Reset, and Reuse ArraysTo clear a VBA array, use Erase arrayName. For a dynamic array, Erase releases its allocated storage; for a fixed-size array, it…
- Auto Macro Recorder in Excel: How to Record and Use ItExcel’s macro recorder captures supported actions as VBA code, letting you replay a routine instead of repeating it by hand. In Microsoft…
- VBA Range Type: What It Means and How to Use It in ExcelIn Excel VBA, Range is an object type: it represents one cell, a group of cells, or a larger range on a…
- AI Macro Recorder: How It Works and What to CheckAn AI macro recorder is a tool that helps automate repeated computer tasks by capturing actions, interpreting instructions, or generating automation steps…
- Excel VBA Popup Message: Show a MsgBox in a MacroTo show a popup message in Excel VBA, use the MsgBox function in a macro, such as MsgBox "Finished", vbInformation, "Update complete".…
- Word VBA: Add a Text Watermark with a MacroYes. In Word for Microsoft 365 on Windows, you can use VBA to add a text watermark by placing a rotated WordArt…
- Word VBA Mail Merge: How to Automate ItWord VBA can automate a mail merge by telling a prepared Word merge document to create a new document containing the merged…
- Word VBA: Remove Formatting While Keeping StylesTo remove direct formatting from selected text in Word VBA while keeping its assigned styles, reset both its character and paragraph formatting:…