VBA & macros
Automate repeat work with macros and VBA code.
- Trim Excel Macro: Clean Extra Spaces in Selected CellsIf the text is in A2, enter =TRIM(A2) in another cell to remove leading and trailing ordinary spaces and reduce repeated spaces…
- Excel VBA Trim Text: What It Removes and How to Use ItIn Excel VBA, use Trim$(textValue) to remove ordinary spaces at the beginning and end of a string; it leaves spaces between words…
- Right in Excel VBA: Syntax, Examples, and TipsIn Excel VBA, Right returns a specified number of characters from the end of a string. For example, Right$(sourceText, 4) returns the…
- Left in Excel VBA: Syntax, Examples, and Common IssuesIn Excel VBA, Left returns a specified number of characters from the beginning of a string. For example, Left("Excel VBA", 5) returns…
- LEFT Excel Macro: Formula and VBA ExplainedLEFT is not an Excel macro: it is a worksheet function that returns a specified number of characters from the start of…
- Concat in Excel VBA: Join Text with the & OperatorTo concatenate text in Excel VBA, use the ampersand operator, &, to join values, such as fullName = firstName & " "…
- COUNTIF in Excel VBA: Syntax, Examples, and TipsIn Excel VBA, count cells that meet one condition with Application.WorksheetFunction.CountIf(range, criteria). For example, if A2:A100 contains status values, VBA can count…
- Excel VBA Match: How It Works and How to Use It SafelyIn Excel VBA, Match finds a value in a one-dimensional range and returns its position within that range—not the value itself. Call…
- Excel to PowerPoint VBA: How to Automate SlidesExcel VBA can automate PowerPoint on Windows: select worksheet ranges, copy them, create slides, and paste the content into a new presentation.…
- Writing VBA for Pivot Tables in Excel: A Practical GuideYes—you can write VBA to create, refresh, and configure Excel PivotTables, including their row, column, and value fields. In Excel for Microsoft…
- VBA UserForm InputBox: How to Get User InputIn Excel VBA, a UserForm does not have a special “InputBox” control: add a TextBox for entry and buttons such as OK…
- VBA Turn Off AutoFilter in Excel Without Losing DataTo turn off a worksheet AutoFilter in VBA, first show all rows if a filter is active, then set the worksheet’s AutoFilterMode…
- VBA PivotTable Field Name Is Not Valid: Causes and FixesThe “PivotTable field name is not valid” message usually means Excel cannot read a proper heading for every column in the source…
- VBA Sort Worksheets Alphabetically: Code and SetupYes. In Excel for Microsoft 365 on Windows, VBA can sort a workbook’s worksheet tabs alphabetically; the macro below compares worksheet names…
- VBA Sort Table by Column: Code and Common FixesTo sort an Excel table by one column with VBA, get the table and column by name, clear any old sort fields,…
- VBA Sort Table: Excel Code, Options, and Common IssuesTo sort an Excel table with VBA, get the table as a ListObject, add one or more sort fields, and apply the…
- VBA Sort Syntax: Examples for Excel RangesIn Excel VBA, the basic sort syntax is Range.Sort: specify the range to rearrange, a key column, its sort order, and whether…
- VBA Sort String Array: Methods, Code, and ExamplesVBA has no built-in general-purpose routine for sorting a string array, but you can sort one with a short insertion-sort procedure. The…
- VBA Sort Sheet: How to Sort Excel Data with a MacroTo sort a sheet with VBA, define the complete data range, add the column or columns to sort by, and apply the…
- VBA Sort Sheets Alphabetically: Macro and StepsYes. In Excel for Microsoft 365 on Windows, a short VBA macro can sort a workbook’s sheet tabs alphabetically from A to…
- VBA Sort Selection in Excel: Code and Common FixesTo sort a selected range in Excel with VBA, use the range’s Sort method and specify a sort key, order, and header…
- VBA Sort Range by Column: Practical Examples and TipsTo sort a range by one column in Excel VBA, call the range’s Sort method and specify the key column, sort order,…
- VBA Sort Range by Two Fields in ExcelTo sort an Excel range by two fields in VBA, add two sort keys in priority order, set the full range to…
- VBA Sort Oldest to Newest: Dates and MacrosTo sort dates from oldest to newest with VBA, sort the full data range by its date column in ascending order: set…
- VBA Sort Key1: How to Sort a Range by One Column in ExcelIn Excel VBA, Key1 is the first column or row Excel uses to decide the sort order when you call the Range.Sort…
- VBA Sort Key: How Key1 and SortFields WorkIn VBA, a sort key is the cell or range that tells Excel which column’s values to use when ordering rows. In…
- VBA Sort Header: Keep Column Headings in Place When SortingTo keep a header row out of the sorted data in Excel VBA, set the sort option to Header:=xlYes. For example, sort…
- VBA Sort in Two Columns: Code, Steps, and Key OptionsYes. In Excel VBA, sort the complete data range and pass two keys to its Sort method: the first key sets the…
- VBA Sort Dictionary Keys: Methods and ExamplesTo sort VBA dictionary keys, copy them into the array returned by Dictionary.Keys, sort that array, and loop through it. A Scripting.Dictionary…
- VBA Sort: How to Sort Excel Data Safely with a VBA MacroVBA does not have a standalone Sort function for worksheet data; in Excel macros, sorting is usually done with the worksheet’s Sort…