VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Delete Whole Row: Safe Methods and ExamplesTo delete an entire worksheet row with VBA, use Rows(row_number).Delete, such as Rows(5).Delete for row 5. In a macro, qualify the row…
- Excel VBA Delete a Workbook: Safe Methods and CodeYes. Excel VBA can delete a workbook file from disk, but the workbook must be closed first: Workbook.Close closes it, while VBA’s…
- Excel VBA Delete Worksheet: Code, Safety, and OptionsTo delete a worksheet with Excel VBA, call that worksheet’s Delete method. Excel normally displays a confirmation prompt; you can suppress it…
- Excel VBA: Delete a Row and Shift UpTo delete a complete worksheet row in Excel VBA and move the rows below it up, use Rows(rowNumber).Delete, such as ws.Rows(5).Delete. To…
- Excel VBA: Delete Rows Based on CriteriaTo delete Excel rows that meet a condition, loop through the relevant rows from bottom to top and delete each match; working…
- Excel VBA: Delete Visible Rows After AutoFilterTo delete only the rows currently visible in a standard Excel AutoFilter, use VBA to take the filter range without its header,…
- Excel VBA: Delete a Row If a Cell Is BlankYes. In Excel VBA, loop through the rows from the bottom upward and delete a row when the chosen cell is blank.…
- Excel VBA: Delete a Range of Rows by Number or MatchTo delete worksheet rows with Excel VBA, use Rows("3:7").Delete for rows 3 through 7, or qualify the range with a worksheet, such…
- Excel VBA: Delete Rows Based on a Cell Value MatchTo delete worksheet rows when a cell matches a value, loop upward from the last used row and delete each match. In…
- Excel VBA: Delete a Row from a TableTo delete a data row from an Excel table with VBA, use the table’s ListRows collection: for example, tbl.ListRows(3).Delete removes the third…
- Excel VBA: Delete a PivotTable SafelyTo delete a PivotTable with VBA, clear its full report range: use pt.TableRange2.Clear after setting pt to the PivotTable you want to…
- Excel VBA: How to Delete the Current RowTo delete the worksheet row containing the active cell, use VBA’s ActiveCell.EntireRow.Delete method. For a safer macro that asks before deleting, save…
- Excel VBA: Delete the Active Row SafelyTo delete the active row with Excel VBA, use ActiveCell.EntireRow.Delete; this removes the entire worksheet row containing the selected cell and shifts…
- Excel VBA: How to Delete a Worksheet ButtonTo delete a button from an Excel worksheet, select the button itself and press Delete; for a Form Control button, right-click it…
- Excel VBA: How to Delete Column and Cell Ranges SafelyTo delete entire columns with Excel VBA, use a worksheet-qualified range such as ws.Columns("B:D").Delete. To delete only cells within a range, use…
- Excel VBA Date to Number: Convert Dates to SerialsIn Excel VBA, convert a Date value to a number with CDbl(dateValue). The result is a serial value: its whole-number part represents…
- Excel VBA Day From Date: Weekday Numbers and NamesIn Excel VBA, use Day(dateValue) to return the day of the month, such as 14, and Weekday(dateValue, vbMonday) to return the day…
- Excel VBA: Get the Day of the Week from a Date ValueIn Excel VBA, use Weekday to get a date’s weekday number and WeekdayName to turn that number into a name. For example,…
- Excel VBA Date and Time Variable TypesIn Excel VBA, use the Date data type for a calendar date, a time, or a date-and-time value; it stores all three…
- Excel VBA Data Validation List From a Range in CellsTo create an Excel drop-down list from a range with VBA, use the target cell’s Validation.Add method and set Type:=xlValidateList and Formula1…
- Excel VBA Date Difference: Calculate Days and MonthsIn Excel VBA, use DateDiff to count calendar boundaries between two dates, for example DateDiff("d", startDate, endDate) for days or DateDiff("m", startDate,…
- Excel VBA Current Worksheet: ActiveSheet ExplainedIn Excel VBA, the current worksheet is usually the sheet the user is looking at, and VBA refers to it as ActiveSheet.…
- Excel VBA Data Validation Drop-Down Lists: How to Build ThemTo create an Excel data-validation drop-down list with VBA, apply the xlValidateList validation type to the target cells and set its source…
- Excel VBA Data Validation List: Setup and ExamplesIn Excel for Microsoft 365 on Windows, create a VBA dropdown by applying data validation with Type:=xlValidateList and setting Formula1 to either…
- Excel VBA: Create a New Workbook with Workbooks.AddTo create a new workbook in Excel VBA, use Set wbNew = Workbooks.Add. This opens a workbook in the current Excel instance;…
- Excel VBA Current Date: Date, Now, Formatting, and ExamplesIn Excel VBA, use Date to get the computer’s current date, without a time; use Now to get the current date and…
- Excel VBA Current Date and Time: Use Now, Date, and TimeIn Excel VBA, use Now to get the current date and time, Date for the current date, or Time for the current…
- Excel VBA: Count Visible Rows After AutoFilterTo count rows still visible after an AutoFilter, loop through the filter’s data rows and count those whose worksheet rows are not…
- Excel VBA: Copy a Worksheet and Rename ItTo copy a worksheet and rename the copy with VBA, use the worksheet’s Copy method, then set the new sheet’s Name property.…
- Excel VBA: Copy a Worksheet to Another Workbook SafelyTo copy a worksheet from one open workbook to another in Excel VBA, use the worksheet’s Copy method and specify a position…