VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA String Limit: Maximum Length and Cell CapsA variable-length VBA String can hold up to approximately 2 billion characters in theory, but available memory usually becomes the practical limit…
- Excel VBA String to Number: Safe Conversion MethodsIn Excel VBA, convert text that represents a number with a conversion function such as CDbl for decimals or CLng for whole…
- Excel VBA Date Subtraction: Get the Number of DaysIn Excel VBA, subtract one date from another with days = endDate - startDate; for dates without times, the result is the…
- Excel VBA String Character Limit: What Really AppliesIn Excel VBA, a variable-length String can hold roughly 2 billion characters in theory, but available memory and the application impose practical…
- Excel VBA String Comparison: Rules, Methods, and ExamplesIn Excel VBA, compare strings with StrComp when you want to choose case sensitivity explicitly: use StrComp(firstText, secondText, vbTextCompare) = 0 for…
- Excel VBA Like Operator: Pattern Matching ExplainedYes. In Excel VBA, the Like operator compares a string with a pattern, letting you test for text such as an invoice…
- Excel VBA: Stop Copy and Paste ModeTo stop Excel’s moving copy border and exit copy or cut mode in VBA, set Application.CutCopyMode to False. Put that statement after…
- Excel VBA Sort Method of Range Class Failed: Fixes“Sort method of Range class failed” is usually Excel’s run-time error 1004: a VBA sort request could not be applied to the…
- Excel VBA Sort Order: Ascending, Descending, and CustomIn Excel VBA, set a sort field’s Order to xlAscending or xlDescending to choose its direction. For a reliable sort, define the…
- Excel VBA Sort A to Z: Code, Options, and Common FixesTo sort a list A to Z with Excel VBA, sort the entire data range by its chosen column and set the…
- Excel VBA Sort Custom Order: How to Set It UpTo sort rows in a custom sequence with Excel VBA, add a sort field with the CustomOrder argument, such as CustomOrder:="Urgent,High,Normal,Low". The…
- Excel VBA Sort and Filter: Practical ExamplesTo sort or filter Excel data with VBA, use the worksheet’s Sort object to rearrange rows and the AutoFilter method to show…
- Excel VBA: Set a PivotTable Filter ValueTo set a PivotTable report filter with VBA, get the PivotField and assign its item to CurrentPage: for example, pf.CurrentPage = "West".…
- Excel VBA Shortcut Key: Open the Editor and Run MacrosIn Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic for Applications (VBA) editor. On a Mac, press…
- Excel VBA: Show a UserForm When the Workbook OpensTo show an Excel VBA UserForm when a workbook opens, put a Workbook_Open event procedure in the ThisWorkbook code module and call…
- Excel VBA: Send Emails Through Outlook AutomaticallyYes. Excel VBA can create and send email through Outlook on Windows by automating the classic Outlook desktop app. The usual method…
- Excel VBA to Send Email in Outlook 365: Setup and CodeYes. In Excel for Microsoft 365 on Windows, VBA can create and send an email through the classic Outlook desktop app using…
- Excel VBA: Set the Active Workbook as a VariableIn Excel VBA, declare a variable as a Workbook and assign the active workbook with Set wb = Application.ActiveWorkbook. For example, use…
- Excel VBA: Select a Range Using VariablesIn Excel VBA, use variables inside Cells(row, column) and pass the two cell references to Range to build a range dynamically. For…
- Excel VBA Select Range Using Cells: Examples and TipsIn Excel VBA, use Cells(rowNumber, columnNumber) to identify a cell, then call Select on that cell or on a range built from…
- Excel VBA Send Email in New Outlook: What Actually WorksExcel VBA cannot directly automate the new Outlook for Windows: the new app does not provide the classic Outlook COM automation interface…
- Excel VBA: Save a Workbook as a New File with SaveAsTo save an Excel workbook as a new file with VBA, use the workbook’s SaveAs method and supply a new filename and,…
- Excel VBA: Save a Worksheet as a New File SafelyTo save one Excel worksheet as a separate file with VBA, copy it to a new workbook with the worksheet’s Copy method,…
- Excel VBA: How to Save a Backup Copy of a WorkbookTo save a backup copy of the workbook that contains your VBA code, use ThisWorkbook.SaveCopyAs fullPath. For example, a macro can make…
- Excel VBA Range Using Cells: Syntax, Examples, and TipsIn Excel VBA, use Cells(row, column) to identify a cell by its row and column numbers, and pass two Cells references to…
- Excel VBA Range Syntax: Examples and Best PracticesIn Excel VBA, a range is a cell or group of cells, usually referenced with Range("A1") or Range("A1:C5"). For dependable code, qualify…
- Excel VBA Reset Error Handling: What Err.Clear DoesTo turn off an active VBA error handler in the current procedure, use On Error GoTo 0. Use Err.Clear to clear the…
- Excel VBA Range Find Exact Match with xlWhole ExplainedTo find a cell whose entire contents match a value in Excel VBA, call Range.Find with LookAt:=xlWhole, and check whether the returned…
- Excel VBA Range Interior Color: Set and Read Cell FillsIn Excel VBA, use the Interior.Color property to set or read a cell’s fill color: for example, Range("A1").Interior.Color = RGB(255, 0, 0)…
- Excel VBA Range of Worksheet Failed: Causes and FixesThe message Method 'Range' of object '_Worksheet' failed is usually Excel’s Run-time error 1004: VBA could not resolve or use the range…