VBA & macros
Automate repeat work with macros and VBA code.
- VBA Loop Through Dictionary Keys: Examples and TipsTo loop through the keys in a VBA Scripting.Dictionary, use For Each with a Variant control variable: For Each key In dict.Keys.…
- VBA Loop Through Dictionary Items: Keys, Values, and TipsTo loop through a VBA dictionary’s entries, use For Each on its keys, then retrieve each associated value with dict(key). To loop…
- VBA Insert Pivot Table in Excel: Practical Code GuideTo insert a PivotTable with VBA in Excel for Microsoft 365 on Windows, create a PivotCache from your source range, create a…
- VBA Jump to Next Loop: How to Skip an IterationVBA has no built-in Continue For or Continue Do statement. To jump to the next loop iteration, put the remaining work inside…
- VBA Left Function: How to Return Text from the StartIn VBA, use Left(string, length) to return a specified number of characters from the beginning of a string. For example, Left("AB-8421", 2)…
- VBA InputBox Password: How to Hide Typed TextInputBox in VBA has no password or masking option: it displays whatever the user types. In Excel for Microsoft 365 on Windows,…
- VBA InputBox Prompt: Syntax, Examples, and Common FixesIn VBA, use the InputBox function to display a prompt and collect text from a user: assign its result to a variable,…
- VBA InputBox Yes/No Questions: Use MsgBox CorrectlyVBA’s standard InputBox cannot display Yes and No buttons; it collects text instead. To ask a true yes-or-no question in Excel VBA,…
- VBA InputBox: What OK and Cancel ReturnIn VBA, the standard InputBox function returns an empty string when the user clicks either OK with no text or Cancel, so…
- VBA InputBox Options: Types, Syntax, and ExamplesExcel VBA offers two main input-box choices: the built-in InputBox function for a simple text response, and Application.InputBox when you need to…
- VBA InputBox: How to Collect Multiple InputsVBA’s standard InputBox collects one response per prompt; it does not display several separate fields in a single dialog. To get multiple…
- VBA InputBox: How It Works, Limits, and When to UseYes—VBA’s InputBox is fine for a quick, simple prompt, such as asking for a name or a short note. Its main limitation…
- VBA InputBox Integer: Get and Validate Whole NumbersVBA’s standard InputBox returns text, not an Integer. In Excel VBA, use Application.InputBox with Type:=1 to request a number, then check that…
- VBA InputBox Dropdown: What Works and What to UseNo: VBA’s built-in InputBox does not have a dropdown control, and Excel’s Application.InputBox does not add one. To let someone choose from…
- VBA InputBox Function: Syntax, Examples, and LimitsThe VBA InputBox function displays a dialog box that asks a user to enter text, then returns the response as a string.…
- VBA InputBox Default Value: Set and Use ItIn VBA, set an InputBox’s default value with its third argument: InputBox(prompt, title, default). For example, InputBox("Enter a quantity:", "Order", "1") opens…
- VBA InputBox Default: How to Set It and Handle CancelIn VBA, set an InputBox default by supplying the third argument: InputBox(prompt, title, default). That value appears in the text field when…
- VBA InputBox Cancel: Exit a Sub SafelyYes. To stop a VBA procedure when the user cancels an input prompt, test the prompt’s return value and then use Exit…
- VBA InputBox Cancel: Detecting Cancel and Blank RepliesIn VBA, the built-in InputBox function returns an empty string when the user clicks Cancel, but it also returns an empty string…
- VBA Include Quotes in a String: Examples and FixesTo include a double quotation mark inside a VBA string, double it in the string literal: write message = "She said ""Hello."""…
- VBA Import CSV in Excel: Methods, Code, and FixesTo import a CSV file with VBA in Excel for Microsoft 365 on Windows, use Workbooks.OpenText to parse the file, then copy…
- VBA Import CSV Files: Methods, Code, and Common IssuesTo import a CSV file with VBA, use Excel’s Workbooks.OpenText method to parse it with the correct delimiter and encoding. The macro…
- VBA Hide UserForm: Methods, Code, and When to Use ThemTo hide an Excel VBA UserForm without unloading it, call Me.Hide from code inside the form. The form disappears but stays loaded,…
- VBA Go To Next Iteration: Skip Loop Code CorrectlyVBA has no built-in Continue For or Continue Do statement. To move to the next iteration, either put the remaining loop work…
- VBA Go to Next Item in a For LoopVBA does not have a Continue For statement. To skip the rest of the current pass and move to the next item,…
- VBA Global Dictionary: Scope, Setup, and Code ExamplesVBA has no built-in global dictionary type, but in Excel for Microsoft 365 on Windows you can create a Scripting.Dictionary object and…
- VBA Get Length of String: How the Len Function WorksTo get the length of a string in VBA, use the Len function: Len(myText) returns the number of characters in the string.…
- VBA Get Character From String: Mid, Loops & TipsTo get one character from a VBA string by position, use Mid$(text, position, 1). For example, Mid$("Excel VBA", 7, 1) returns V;…
- VBA UserForms: What They Are and How to Use ThemA VBA UserForm is a custom dialog window you build in the Visual Basic for Applications editor and use to collect or…
- VBA Format Date String: Examples, Patterns, and FixesIn VBA, use Format or Format$ to turn a date value into a text string: for example, Format$(Date, "yyyy-mm-dd") produces a year-month-day…