VBA & macros
Automate repeat work with macros and VBA code.
- VBA Could Not Find File? Causes, Checks, and FixesIf VBA says it could not find a file, the path or filename supplied to the macro does not resolve to an…
- VBA Create New Workbook: Code, Options, and Tips in ExcelTo create a new Excel workbook with VBA, use Workbooks.Add. For example, Set newWb = Workbooks.Add creates a workbook using Excel’s default…
- VBA Create New Workbook With Name: A Practical GuideIn Excel VBA, create a workbook with Workbooks.Add, then give it a lasting name and location with SaveAs. For example, create a…
- VBA Copy and Paste Worksheet: Practical ExamplesTo copy an entire worksheet in Excel VBA, use the worksheet’s Copy method and specify where the copy should go: Worksheets("Sales").Copy After:=Worksheets(Worksheets.Count)…
- VBA Copy PasteSpecial: Values, Formats, and MoreIn Excel VBA, copy a range and call PasteSpecial on the destination to paste only values, formats, formulas, or another selected part…
- VBA Copy Range and Paste as Values in ExcelTo copy an Excel range and paste only its values with VBA, copy the source range and use PasteSpecial with xlPasteValues. For…
- VBA Copy and Paste Values Across All Excel Tabs SafelyYes. In Excel for Microsoft 365 on Windows, a VBA macro can take the selected range on the active worksheet and write…
- VBA Copy Visible Cells: How to Paste Filtered Rows in ExcelYes. In Excel VBA, use SpecialCells(xlCellTypeVisible) on the source range, then copy that result and paste it at the destination. This copies…
- VBA Copy and Paste to the Last Available RowTo copy data with VBA to the first available row after existing data, find the last occupied row in a reliable column…
- VBA Copy and Paste a Range of Cells in ExcelTo copy a range of cells with VBA, use sourceRange.Copy Destination:=destinationRange. For example, Worksheets("Sheet1").Range("A1:C10").Copy Destination:=Worksheets("Sheet2").Range("A1") copies the range to the other sheet,…
- VBA Copy Paste Row: Excel Code and Common FixesTo copy an entire row to another row in Excel with VBA, use Rows(sourceRow).Copy Destination:=Rows(targetRow). For example, Worksheets("Data").Rows(5).Copy Destination:=Worksheets("Data").Rows(10) copies row 5…
- VBA Copy and Paste a Sheet: Code and OptionsTo copy a worksheet with VBA, use the sheet’s Copy method and specify where the duplicate should go. For example, Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)…
- VBA Copy and Paste Excel Cells Into the Email BodyYes. In Excel for Microsoft 365 on Windows, VBA can copy a cell range and paste it into a message in classic…
- VBA Copy Paste Formats: Methods and ExamplesIn Excel VBA, copy formatting without changing cell contents by copying a source range and pasting with Paste:=xlPasteFormats. The basic pattern is…
- VBA Copy Paste Mode: How to Clear and Control ItIn Excel VBA, copy/paste mode is Excel’s temporary state after a cell or range has been copied or cut. Check it with…
- VBA Copy and Paste Data Between Excel SheetsTo copy a range from one Excel worksheet to another with VBA, use a macro that names both sheets and copies the…
- VBA Copy Paste Destination: How to Set the Target RangeIn VBA, specify the destination range with the Destination argument of Range.Copy: for example, Worksheets("Data").Range("A1:C5").Copy Destination:=Worksheets("Report").Range("E1"). The destination is the top-left cell…
- VBA Copy and Paste Values Only: Practical Methods and CodeTo copy values only with VBA, assign the source range’s values to an equally sized destination range: destinationRange.Value = sourceRange.Value. This writes…
- VBA Copy Dictionary: Methods, Code, and Deep CopiesTo copy a VBA Scripting.Dictionary, create a second dictionary and add each key and item from the first; there is no built-in…
- VBA Copy and Paste Values Only in ExcelTo copy a range in Excel VBA and paste only its values, use Copy followed by PasteSpecial Paste:=xlPasteValues. For example, sourceRange.Copy and…
- VBA Copy and Paste Values Into the Next Empty Row in ExcelTo copy a range as values into the next empty row in Excel, assign the source range’s .Value to a same-sized destination…
- VBA Copy and Paste Cells: Examples and TipsIn Excel VBA, copy cells with the Copy method: specify a source range and a destination, such as sourceRange.Copy Destination:=destinationCell. To paste…
- VBA Copy and Paste a File: Practical Code and Safe StepsTo copy a file with VBA in Excel for Microsoft 365 on Windows, use the FileCopy statement or FileSystemObject.CopyFile. Give the code…
- VBA Copy and Paste Special: Examples and OptionsIn Excel VBA, copy a range and paste only selected content with Range.Copy followed by Range.PasteSpecial. For example, use Destination.PasteSpecial Paste:=xlPasteValues to…
- VBA Convert String to Number: Functions and ExamplesTo convert numeric text to a number in VBA, use a conversion function such as CDbl for decimal values, CLng for whole…
- VBA Code to Send Email from Excel Using Gmail SMTPYou can send email from Excel VBA through Gmail’s SMTP server using the Windows CDO library: create a Gmail app password, configure…
- VBA Code Workbook Open: How to Run Macros at StartupTo run VBA when an Excel workbook opens, put a Workbook_Open event procedure in that workbook’s ThisWorkbook code module, then save the…
- VBA Code to Disable Copy and Paste in ExcelIn Excel for Microsoft 365 on Windows, VBA can intercept common copy, cut, and paste shortcuts such as Ctrl+C and Ctrl+V. It…
- VBA Code to Disable Copy and Paste in ExcelTo block the usual copy-and-paste keyboard shortcuts in Excel for Microsoft 365 on Windows, use VBA’s Application.OnKey method to disable Ctrl+C and…
- VBA Code to Copy and Paste Data in Excel: ExamplesTo copy a range to another worksheet with VBA, use Range.Copy and specify the destination: sourceSheet.Range("A1:D20").Copy Destination:=destinationSheet.Range("A1"). This copies the cells, including…