You can copy data in Excel VBA with a single line: Range("A1:B10").Copy Destination:=Range("D1"). That copies values, formulas and formatting from one range to another on the same sheet. For most real work you will want to control exactly what gets copied (values only, or into the next empty row), and that is what the steps below cover. Nothing needs installing first — the VBA editor is already in Excel — but you do need to enable the Developer tab and save your workbook as a macro-enabled file (.xlsm), otherwise your code is lost when you close it.
What You'll Need
- Excel for Windows or Mac (the VBA editor is built in; the menu labels below are for the Windows desktop version and can differ slightly by version, device or region).
- The Developer tab visible: File > Options > Customize Ribbon, then tick Developer in the right-hand list. On Mac, Excel > Preferences > Ribbon & Toolbar.
- A workbook saved as Excel Macro-Enabled Workbook (*.xlsm).
- Macro security set to allow your own macros: Developer > Macro Security. Do not lower this for files you did not create.
Step-by-Step
- Open the VBA editor. Press Alt+F11 (on Mac, Fn+Alt+F11 or Developer > Visual Basic). The editor opens in its own window.
- Insert a module. In the editor, use Insert > Module. A blank code pane appears. Code in a standard module can be run from anywhere in the workbook; code in a sheet module only makes sense for that sheet.
- Write the simplest copy statement. Type:
Sub CopyRange()Range("A1:B10").Copy Destination:=Range("D1")End Sub
This copies A1:B10 and pastes it starting at D1, keeping formatting. Both ranges must be on the active sheet unless you qualify them with a worksheet name. - Run it. Click inside the subroutine and press F5, or use Run > Run Sub/UserForm. Switch back to Excel (Alt+F11 again) to see the result.
- Copy values only, not formatting. The one-line Copy method always brings formatting. To paste values only, split it into two statements:
Range("A1:B10").CopyRange("D1").PasteSpecial Paste:=xlPasteValuesApplication.CutCopyMode = False
The last line clears the marching-ants border; without it, Excel stays in copy mode and later actions can paste unexpectedly. - Copy to another sheet. Qualify both sides so the code does not depend on which sheet happens to be active:
Worksheets("Source").Range("A1:B10").Copy _Destination:=Worksheets("Target").Range("A1")
Replace the names in quotes with your actual tab names. - Paste into the next empty row. This is the pattern for appending records. Find the last used row in column A of the destination, add one, and paste there:
Dim nextRow As LongnextRow = Worksheets("Target").Cells(Rows.Count, 1).End(xlUp).Row + 1Worksheets("Source").Range("A2:B2").Copy _Destination:=Worksheets("Target").Cells(nextRow, 1)
Note the+ 1: without it you overwrite the last row. - Copy a variable-sized range. Hard-coded addresses break when data grows. Use the last-row technique on the source too:
Dim lastRow As LonglastRow = Worksheets("Source").Cells(Rows.Count, 1).End(xlUp).RowWorksheets("Source").Range("A1:B" & lastRow).Copy _Destination:=Worksheets("Target").Range("A1") - Copy an entire column or row. Use
Columns("A").Copy Destination:=Columns("D")orRows(1).Copy Destination:=Rows(5). Whole-column copies are slow on large sheets; a bounded range is faster. - Copy between workbooks. Open both, then qualify with the workbook:
Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("A1:B10").Copy _Destination:=Workbooks("Book2.xlsm").Worksheets("Sheet1").Range("A1"). If a name contains spaces, keep the quotes. - Turn off screen flicker for loops. If you copy inside a loop, wrap the loop with
Application.ScreenUpdating = Falseat the start and set it back toTrueat the end. Also setApplication.CutCopyMode = Falseafter the loop. Always restore ScreenUpdating, even if an error occurs, or Excel stays in a blank-looking state. - Save and test. Press Ctrl+S, close the editor, and run the macro from Developer > Macros to confirm it works outside the editor.
Common Mistakes
- Forgetting the destination.
Range("A1").Copyon its own leaves data on the clipboard; nothing appears until you paste. Always supplyDestination:=or a following PasteSpecial. - Leaving Excel in copy mode. The dashed border around the source confuses users and can cause an accidental paste later. Clear it with
Application.CutCopyMode = False. - Assuming the active sheet. Unqualified
Rangecalls act on whatever sheet is active. If a user clicks another tab, the macro copies the wrong data. Qualify withWorksheets("Name"). - Overwriting the last row. Forgetting
+ 1when finding the next empty row silently replaces existing records. - Copying formats you did not want. The plain Copy method carries borders, fills and number formats. Use PasteSpecial with xlPasteValues when only the data matters.
- Saving as .xlsx. Excel warns that macros cannot be saved; if you click through and save as .xlsx, the code is stripped. Keep the file as .xlsm.
- Copying merged cells. Copying a range that only partly overlaps a merged area raises an error. Unmerge first or copy the whole merged block.
Tips
- Use
Range("A1").CurrentRegionto grab a contiguous block of data without calculating the last row. - For very large copies, assigning values directly (
Range("D1:F10").Value = Range("A1:C10").Value) is faster than Copy and skips the clipboard entirely. - Name your ranges (Formulas > Define Name) and refer to them in code, so moving data does not break the macro.
- Add
Option Explicitat the top of the module so undeclared variables are flagged — most "wrong range" bugs start as a typo in a variable name. - Keep one small subroutine per job and call them from a master routine; it makes debugging far easier than one long block.
Troubleshooting
"Subscript out of range" (Error 9). A worksheet or workbook name in quotes does not match reality — check spelling, trailing spaces and whether the sheet exists in the active workbook.
"Application-defined or object-defined error" (Error 1004). Usually an invalid range address, a protected sheet, or a destination that overlaps the source. Unprotect the sheet first (Review > Unprotect Sheet) and check the addresses.
Nothing happens when you run it. The cursor may not be inside the right subroutine, or macros are disabled. Check Developer > Macro Security and confirm the file is .xlsm.
Data lands in the wrong place. Print the addresses with Debug.Print Range("A1").Address and read the result in the Immediate window (View > Immediate Window, Ctrl+G). This shows exactly which sheet and range the code is using.
Excel looks frozen or blank after running. ScreenUpdating was probably left off by an error. In the Immediate window type Application.ScreenUpdating = True and press Enter.
If that did not work, step through the code line by line with F8 to see where it stops, and check whether the workbook is shared or read-only — both block copy operations.
Frequently Asked Questions
How do I copy only values in VBA?
Use Range("A1:B10").Copy followed by Range("D1").PasteSpecial Paste:=xlPasteValues, then Application.CutCopyMode = False. The plain Copy method with a Destination always carries formatting.
Can I copy data without using the clipboard?
Yes. Assign the Value property directly: Range("D1:F10").Value = Range("A1:C10").Value. This is faster and avoids leaving Excel in copy mode.
Why does my macro copy from the wrong sheet?
Because an unqualified Range refers to the active sheet. Add Worksheets("SheetName") in front of every range reference.
How do I paste into the next empty row?
Find the last used row with Cells(Rows.Count, 1).End(xlUp).Row, add 1, and use that number as the destination row.
Does this work in Excel for Mac?
The VBA language is the same, but menu paths and some keyboard shortcuts differ. Use the Developer tab rather than Alt+F11 if the shortcut does not respond.
Can I copy between two open workbooks?
Yes, as long as both are open and you qualify each range with its Workbooks("name") and Worksheets("name"). Copying from a closed workbook requires opening it first.