VBA & macros
Automate repeat work with macros and VBA code.
- VBA Excel Send Email Without Outlook?Yes. In Excel for Microsoft 365 on Windows, a VBA macro can send email without Outlook by connecting directly to an SMTP…
- VBA: Filter a PivotTable by Cell Value AutomaticallyTo filter an Excel PivotTable from a cell, use VBA to read that cell and assign its value to the PivotField’s CurrentPage…
- VBA Filter and Sort in Excel: Code and Key DetailsTo filter and sort a worksheet with VBA, use the AutoFilter method to show matching records and the worksheet’s Sort object to…
- VBA Excel Delete Range: Clear or Shift Cells?To delete a range in Excel VBA and move the remaining cells up, use Range("B2:D5").Delete Shift:=xlUp; to move cells left, use Shift:=xlToLeft.…
- VBA Excel: How to Find Unique Values in Two ColumnsTo find distinct values across two Excel columns with VBA, scan both columns into a dictionary and write each value only the…
- VBA Excel Range Copy and Paste Into an Outlook EmailTo copy an Excel range into an Outlook email with VBA, copy the range, display a new message in classic Outlook for…
- VBA Excel: Compare Two Sheets for Differences Step by StepTo compare two Excel sheets with VBA, loop through the cells at matching addresses, compare their contents, and write any mismatches to…
- VBA Excel: Copy a Range of CellsTo copy a range of cells in VBA, use the range’s Copy method and specify the top-left destination cell: sourceRange.Copy Destination:=targetSheet.Range("A1"). This…
- VBA Excel Active Workbook Path: Get It CorrectlyIn Excel VBA, use ActiveWorkbook.Path to get the folder path of the workbook that is active; it does not include the workbook’s…
- VBA Error Handling in Loops: Safe Patterns That WorkIn VBA, use an error handler to decide what a loop should do when one item fails: log the problem and continue,…
- VBA Error Handling Tutorial: Errors, Handlers, and CleanupVBA error handling lets a macro respond to a runtime problem instead of stopping unexpectedly. Start with On Error GoTo HandlerName for…
- VBA Error Handling: On Error, Cleanup, and Debugging TipsVBA error handling lets a macro respond when a statement fails instead of stopping unexpectedly. Use On Error GoTo HandlerName for errors…
- VBA Dictionary vs Collection: Which Should You Use?Use a VBA Dictionary when you need fast lookups by unique key, an Exists check, or easy access to all keys and…
- VBA Error Handling Best Practices for Reliable MacrosVBA error handling is most reliable when each procedure has a clear failure path: use On Error GoTo for unexpected errors, handle…
- VBA Error Handling Examples for Reliable MacrosVBA error handling examples usually use On Error GoTo to catch unexpected failures, On Error Resume Next briefly for an expected failure,…
- VBA Delete Whole Row: Safe Methods and ExamplesTo delete an entire worksheet row with VBA, use Rows(5).EntireRow.Delete, replacing 5 with the row number you want to remove. In a…
- VBA Delete Workbook: Safe Methods and CodeYes. In Excel VBA for Microsoft 365 on Windows, the Kill statement can delete a workbook file by its full path, provided…
- VBA Dictionary Methods: Add, Exists, Keys and MoreA VBA Dictionary stores pairs of unique keys and associated values, and its core methods are Add, Exists, Keys, Items, Remove, and…
- VBA Delete Rows With a Specific Cell Value in ExcelTo delete Excel rows when a cell in a chosen column contains a specific value, loop upward from the last used row…
- VBA Delete Row and Shift Up: Excel Macro ExamplesTo delete an entire worksheet row with VBA and move the rows below it up, use Rows(rowNumber).Delete, such as ws.Rows(5).Delete. To delete…
- VBA Delete Rows in a Range: Safe Methods and ExamplesTo delete entire worksheet rows that intersect a range, use the range’s EntireRow property and call Delete, for example ws.Range("B5:B12").EntireRow.Delete. To remove…
- VBA Delete Row Based on Cell Value in ExcelTo delete Excel rows when a cell contains a chosen value, loop through the worksheet from the bottom row upward and delete…
- VBA Delete Row If Cell Contains TextTo delete rows when a cell contains particular text, use VBA’s InStr function in a loop that checks the target column from…
- VBA Delete Row If Cell Is Blank: Safe MethodsTo delete rows when a cell in a chosen column is blank, loop through the data from the bottom row upward and…
- VBA Delete Dictionary Items, Keys, or the Whole ObjectIn VBA, remove one entry from a Scripting.Dictionary with dict.Remove key, clear every entry but keep the dictionary with dict.RemoveAll, or release…
- VBA Delete an Entire Row Based on Cell Value in ExcelTo delete entire Excel rows when a cell matches a value, loop through the worksheet from the bottom up and delete each…
- VBA Delete First Row: Code and Safe OptionsTo delete row 1 of a worksheet with VBA, use ws.Rows(1).Delete, where ws is the worksheet you intend to change. For example,…
- VBA Delete Current Row: Safe Methods and ExamplesTo delete the current row in Excel with VBA, delete the entire worksheet row that contains the active cell. The basic operation…
- VBA Delete Active Row: Simple Macro, Safety, and TipsTo delete the worksheet row containing the active cell in Excel VBA, call the row’s Delete method. The basic macro below does…
- VBA Create Pivot Table on a New Sheet: Steps and CodeYes. In Excel for Microsoft 365 on Windows, VBA can use the selected data region to create a PivotTable on a newly…