VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Get Workbook Name: Methods and ExamplesIn Excel VBA, use ThisWorkbook.Name to get the name of the workbook that contains the running code, or ActiveWorkbook.Name to get the…
- Excel VBA Get Worksheet by Name: Examples and ErrorsIn Excel VBA, get a worksheet by name with Set ws = ThisWorkbook.Worksheets("Summary"), replacing Summary with the tab name. Use ThisWorkbook when…
- Excel VBA Get Worksheet Index: Methods and ExamplesIn Excel VBA, read a worksheet’s Index property to get its position in the workbook’s sheet-tab order: for example, ThisWorkbook.Worksheets("Data").Index. The number…
- Excel VBA: Get a PivotTable NameIn Excel VBA, get a PivotTable’s name from its Name property: pt.Name. First obtain the PivotTable object from a worksheet’s PivotTables collection,…
- Excel VBA: Get a String from a Cell, Safely and ReliablyTo get a cell’s value as a VBA string, read it into a Variant and convert it with CStr: use Value2 for…
- Excel VBA: Get a Value From a UserForm TextBoxIn Excel VBA, read a UserForm TextBox with its Value property: for example, userName = Me.txtName.Value inside the form, or userName =…
- Excel VBA: Get a PivotTable’s LocationTo get a PivotTable’s location in Excel VBA, use its TableRange2 property and read the range’s address. For example, pt.TableRange2.Address(External:=True) returns the…
- Excel VBA Get Month From Date: Code, Formats, and TipsIn Excel VBA, use the built-in Month function to get the month number from a date: Month(dateValue) returns a number from 1…
- Excel VBA: Get a Named Range’s ValueTo read a workbook-level named range in Excel VBA, get its Range object and read its Value or Value2 property: Set target…
- Excel VBA: Get a Range’s Length in Cells or CharactersIn Excel VBA, use Range.CountLarge to get how many cells a range contains; use Range.Rows.Count and Range.Columns.Count for its dimensions. If by…
- Excel VBA: Get the Date to the Right of a StringIf a cell contains a text label and the date is in the cell immediately to its right, use VBA’s Find method…
- Excel VBA: Get the First Item in a DictionaryTo get the first key from a VBA Scripting.Dictionary, copy its keys into a Variant array and read the first array element:…
- Excel VBA Functions With Multiple Parameters ExplainedTo create an Excel VBA function with multiple parameters, declare each argument in the function’s parentheses, separated by commas, then call the…
- Excel VBA Functions: How They Work and When to Use ThemExcel VBA functions are procedures that perform a calculation or task and return a result; you can write your own functions or…
- Excel VBA Get a Character from a String by PositionTo get one character from a string in Excel VBA, use Mid$(text, position, 1); the position starts at 1, not 0. For…
- Excel VBA Function vs Sub: Differences and ExamplesIn Excel VBA, a Function calculates and returns a value, while a Sub performs an action and does not return a value.…
- Excel VBA Function Parameters: Defaults, ByRef, and MoreIn Excel VBA, a standard function parameter is a named input declared in the function’s parentheses, such as ByVal amount As Double.…
- Excel VBA Function Syntax: Examples and RulesExcel VBA function syntax starts with a Function statement and ends with End Function; the function returns a value by assigning it…
- Excel VBA Functions That Return ArraysYes. In Excel VBA, declare the function as Variant, place an array in that Variant, and assign it to the function name;…
- Excel VBA Function Return Boolean Values: How It WorksYes. An Excel VBA function can return a Boolean value: declare the function with As Boolean, then assign True or False to…
- Excel VBA Function Return Value: Syntax and ExamplesAn Excel VBA function returns a value by assigning that value to the function’s own name before the function ends. For example,…
- Excel VBA Function Return: Values, Syntax, and ExamplesAn Excel VBA function returns a value by assigning that value to the function’s own name; VBA does not use a return…
- Excel VBA Optional Parameters: Syntax and ExamplesYes. In Excel VBA, declare an optional parameter with the Optional keyword, usually followed by a default value, such as Optional ByVal…
- Excel VBA Function Output: Return Values and DisplayAn Excel VBA function outputs a value by assigning that value to the function’s name. That value appears in a worksheet cell…
- Excel VBA Function Not Showing Up? Fixes That WorkIf an Excel VBA function is not showing up, first check that it is a public function in a standard module in…
- Excel VBA Function Not Updating Automatically? Fix ItIf an Excel VBA function is not updating automatically, first check Formulas > Calculation Options > Automatic, then press Ctrl+Alt+F9 to force…
- Excel VBA Optional Arguments: How They WorkYes—Excel VBA procedures and functions can have optional arguments. Declare one with the Optional keyword; give typed arguments a default value, or…
- Excel VBA Function Not Defined? Causes and Fixes ExplainedIf Excel VBA reports Sub or Function not defined, it cannot find the procedure named in the highlighted line. Check the spelling…
- Excel VBA Function Not Recognized? How to Fix ItIf Excel does not recognize a VBA function, first check that it is a Public Function in a standard module in a…
- Excel VBA Minimum: Find the Smallest ValueIn Excel VBA, use Application.WorksheetFunction.Min to return the smallest value from a range or a set of numbers; VBA does not have…