VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Copy Range to Another Sheet: Methods and TipsTo copy a range to another worksheet with Excel VBA, qualify the source and destination sheets and use Range.Copy Destination:=. For example,…
- Excel VBA: How to Copy a UserForm to Another WorkbookTo copy an Excel VBA UserForm to another workbook, export the form from the source workbook’s VBA project and import its .frm…
- Excel VBA Copy Worksheet: Code, Methods, and SafetyTo copy a worksheet with Excel VBA, call the worksheet’s Copy method and specify where the duplicate should go. For example, sourceSheet.Copy…
- Excel VBA: Copy and Paste Values Across a WorksheetTo replace formulas with their current results across a worksheet in Excel for Microsoft 365 on Windows, run a VBA macro on…
- Excel VBA Copy Paste Transpose: Working Code and TipsTo copy a range and paste it transposed with Excel VBA, copy the source range and use PasteSpecial with Transpose:=True. For example,…
- Excel VBA: Copy and Paste Values Without FormulasTo copy a range’s results without its formulas in Excel VBA, copy the source range and use PasteSpecial with xlPasteValues. For example,…
- Excel VBA: Copy and Paste Range ValuesTo copy a range’s results without its formulas or formatting, assign the source range’s Value property to a same-sized destination range’s Value…
- Excel VBA: Copy and Paste Selected Cells with a MacroTo copy selected cells with VBA, call the range’s Copy method and specify a destination cell, as in Selection.Copy Destination:=Range("D5"). The macro…
- Excel VBA Copy Paste Special: Values, Formats, and MoreIn Excel VBA, copy a range and call PasteSpecial on the destination, specifying what to paste. For example, use sourceRange.Copy followed by…
- Excel VBA Copy and Paste a Range to Another WorkbookTo copy a range from one open Excel workbook to another with VBA, use sourceRange.Copy Destination:=targetSheet.Range("B2"), replacing the range, worksheet, and destination…
- Excel VBA Copy and Paste a Range to Another WorksheetTo copy a range to another worksheet with Excel VBA, identify the source and destination worksheets, then use the source range’s Copy…
- Excel VBA Copy an Entire Column: Safe Code and TipsYes. In Excel for Microsoft 365 on Windows, VBA can copy a complete column with a worksheet’s Columns collection and the Copy…
- Excel VBA Copy and Paste Formulas Between Cells SafelyTo copy a formula to another cell with Excel VBA, use Copy followed by PasteSpecial Paste:=xlPasteFormulas. This pastes the formula without copying…
- Excel VBA: How to Copy a Module to Another WorkbookTo copy an Excel VBA module to another workbook, open both files in desktop Excel, press Alt+F11, and copy the module in…
- Excel VBA Copy and Paste Cells: Examples and OptionsTo copy a cell with Excel VBA, use the source range’s Copy method and specify a destination: sourceCell.Copy Destination:=destinationCell. This copies the…
- Excel VBA: Copy a Column and Paste Values Only SafelyTo copy a column in Excel VBA and paste only its values, copy the source column and use PasteSpecial with xlPasteValues. For…
- Excel VBA: Copy the End Part of a String with RightTo copy the last characters of a string in Excel VBA, use the Right$ function: assign Right$(text, numberOfCharacters) to another variable or…
- Excel VBA: Copy an Entire Worksheet into an Array SafelyIn Excel VBA, assign a worksheet range’s Value2 property to a Variant to copy its cell values into a two-dimensional array. For…
- Excel VBA Copy and Paste a Row: Practical Code GuideTo copy a row with Excel VBA, specify the source and destination worksheet rows and use Copy Destination. For example, this copies…
- Excel VBA Copy and Paste Values OnlyTo copy a range in Excel VBA and paste only its values, use Copy followed by PasteSpecial Paste:=xlPasteValues. For a direct transfer…
- Excel VBA: Copy an Array to a Worksheet Range EasilyTo copy a two-dimensional VBA array to cells, assign it to a worksheet range whose size matches the array: Range("A1").Resize(UBound(data, 1), UBound(data,…
- Excel VBA Copy and Paste Range: Examples and TipsIn Excel VBA, copy a range to another location with sourceRange.Copy Destination:=destinationRange. For values only, assign the ranges directly with destinationRange.Value2 =…
- Excel VBA: Copy and Paste a Dynamic Range AutomaticallyTo copy a range that grows or shrinks, use VBA to find its last populated row and column, then copy the resulting…
- Excel VBA: Copy and Paste Filtered Cells Only SafelyYes. In Excel VBA, use SpecialCells(xlCellTypeVisible) on the filtered data range to select cells that remain visible, then copy those cells to…
- Excel VBA Copy and Paste Formatting: Code and TipsTo copy only formatting with Excel VBA, copy the source range and use PasteSpecial with xlPasteFormats: sourceRange.Copy, then destinationRange.PasteSpecial Paste:=xlPasteFormats. This transfers…
- Excel VBA Copy and Paste Formatting Without Changing ValuesTo copy formatting with Excel VBA without copying cell values or formulas, copy the source range and paste with xlPasteFormats. For example,…
- Excel VBA Copy and Paste a Column: Examples and TipsTo copy a column with Excel VBA, use sourceWs.Columns("B").Copy Destination:=targetWs.Columns("D"), replacing the worksheet variables and column letters with yours. This copies the…
- Excel VBA: How to Close a UserForm After a Button ClickTo close an Excel VBA UserForm when a button is clicked, put Me.Hide in that button’s Click event to hide the form,…
- Excel VBA Collection vs Dictionary: Which Should You Use?Use a VBA Collection when you need an ordered list of items, optionally addressed by unique string keys; use a Scripting.Dictionary when…
- Excel VBA Convert Date to Number: Serial ValuesYes. Excel dates are stored as serial numbers, so VBA can read a date cell’s underlying number with Range.Value2; to display that…