VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA: Keep a UserForm on TopTo keep an Excel VBA UserForm above other windows on Windows, call the Windows API function SetWindowPos with the HWND_TOPMOST option when…
- Excel VBA InputBox Dropdown List: What Works InsteadNo: Excel VBA’s standard InputBox cannot display a dropdown list of choices. To offer a real dropdown, use a VBA UserForm with…
- Excel VBA: Insert the Current Date and Time in a CellTo insert a fixed date-and-time timestamp with Excel VBA, assign the VBA function Now to a cell, then apply a number format.…
- Excel VBA Insert Row Below Active Cell: Code and TipsTo insert a complete worksheet row immediately below the active cell in Excel for Microsoft 365 on Windows, run a VBA macro…
- Excel VBA InputBox With Multiple InputsExcel VBA’s built-in InputBox and Application.InputBox each display one input field, not a form with several fields. To collect multiple values, show…
- Excel VBA Input Box to Select a Row by NumberTo select a worksheet row by its number, use VBA’s Application.InputBox with Type:=1, validate the entered number, then select ws.Rows(rowNumber). If you…
- Excel VBA InputBox Types and When to Use EachExcel VBA has two commonly used input boxes: the VBA InputBox function, which returns text, and Application.InputBox, which can require a particular…
- Excel VBA Input Box With a Drop-Down ListExcel’s built-in VBA InputBox cannot display a drop-down list. To let someone choose from fixed options, create a VBA UserForm with a…
- Excel VBA: How to Stop an Infinite Loop Safely in ExcelTo stop a running Excel VBA macro, press Ctrl+Break on Windows, then choose End to stop it or Debug to inspect the…
- Excel VBA Input Box Date Picker: What Actually WorksExcel’s VBA InputBox does not include a calendar or date-picker control: it asks the user to type a response. For Microsoft 365…
- Excel VBA Input Box Dropdown List: Options and SetupExcel’s built-in VBA InputBox does not support a dropdown list. To let someone choose from a visible list, create a VBA UserForm…
- Excel VBA: Get the Number of Sheets in a Workbook EasilyTo get the number of sheets in a workbook with VBA, use the workbook’s Sheets.Count property—for example, ThisWorkbook.Sheets.Count. Use Worksheets.Count instead if…
- Excel VBA: Hide a Column by Number in Your WorksheetTo hide a column by its number in Excel VBA, set that worksheet column’s Hidden property to True. For example, ws.Columns(3).Hidden =…
- Excel VBA Get Array Dimensions: Bounds, Rank, and SizeIn Excel VBA, use LBound(array, dimension) and UBound(array, dimension) to get an array’s lower and upper bounds; its element count in a…
- Excel VBA: Get the Last Day of a MonthIn Excel VBA, use DateSerial(Year(d), Month(d) + 1, 0) to get the final date of the month containing a date. The zero…
- Excel VBA: Get the Current Workbook File Path EasilyIn Excel VBA, use ThisWorkbook.Path to get the folder path of the workbook that contains the code, or ActiveWorkbook.Path to get the…
- Excel VBA Get Current Workbook Name: Code and TipsTo get the name of the workbook currently active in Excel VBA, use ActiveWorkbook.Name. For example, assign Set wb = Application.ActiveWorkbook and…
- Excel VBA Function Name Error: Common Causes and FixesAn Excel VBA function-name error usually means VBA cannot parse or find the procedure name, or Excel cannot recognize a custom function…
- Excel VBA Function Tutorial: Write and Use FunctionsAn Excel VBA function is a procedure that calculates a value and returns it to the code that called it; you can…
- Excel VBA Gantt Chart: Build and Automate a TimelineYes. You can use VBA to build a Gantt-style schedule in Excel by turning task start dates and durations into a calendar…
- Excel VBA Freeze Worksheet: Freeze Panes or Lock CellsIn Excel VBA, use ActiveWindow.FreezePanes to keep rows or columns visible while you scroll; use worksheet protection when you mean to stop…
- Excel VBA Function Examples: Useful Worksheet UDFsExcel VBA function examples show how to create custom worksheet functions for tasks that built-in formulas do not handle conveniently. Add a…
- Excel VBA: Find a Value in a Range and Select Its CellIn Excel VBA, use Range.Find to locate a value, check whether it returned a cell, and then activate the worksheet and select…
- Excel VBA Date Number Format: How to Set ItIn Excel VBA, format a cell or range as a date by setting its NumberFormat property, for example: Range("B2:B100").NumberFormat = "dd-mmm-yyyy". This…
- Excel VBA Freeze Panes at a Specific CellYes. Activate the worksheet, select the cell that marks the top-left corner of the scrolling area, then set ActiveWindow.FreezePanes = True. For…
- Excel VBA Find Value in Range: Examples and TipsTo find a value in an Excel range with VBA, use the range’s Find method, then check whether it returned a cell…
- Excel VBA: Find Unique Values in a ColumnTo find unique values in an Excel column with VBA, loop through the source cells, keep the first occurrence of each value,…
- Excel VBA Find a Value in an Array: Loop, Match, and TipsTo find a value in a VBA array, loop from LBound to UBound and compare each element with the value you want.…
- Excel VBA: Find a Value in a Column and Return Its RowTo find a value in a column with Excel VBA, use the Range.Find method on the cells you want to search. It…
- Excel VBA Find Text in a Range: Code and Examples ExplainedTo find text in an Excel range with VBA, use the range’s Find method and check whether it returns a cell. For…