VBA & Macro Problems

Record an Excel Macro to Copy Data Between Workbooks

Steven ParkerSteven Parker Nov 27, 2026 868 views

Question details

Create an Excel macro that copies data or sparkline images from another workbook into the current workbook or a new one.

Record an Excel Macro to Copy Data Between Workbooks
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user wants to automate a copy operation involving a source workbook and a separate destination workbook.
Observed behavior
The user needs a macro that identifies both workbooks rather than relying only on the active workbook.
Before you start

Open the source workbook and identify its file name, worksheet name, and the range to copy. If you plan to save the macro in a workbook, save that workbook as an Excel Macro-Enabled Workbook (.xlsm).

Solution 1Recommended

Record and edit a macro to copy data into a new workbook

Use the recorder to capture the workflow, then edit the VBA to identify the source explicitly and create a destination workbook.

1
Start recording

In Excel, select View > Macros > Record Macro. Choose where to store the macro, enter a name, and select OK.

2
Perform the copy

Switch to the open source workbook, select the data range, and copy it. Create a new workbook, paste the range into cell A1, and select View > Macros > Stop Recording.

3
Edit the macro

Open View > Macros > View Macros, select the recorded macro, and choose Edit. Replace its code with the following example, changing the source workbook name, sheet name, and range: Sub CopyDataToNewWorkbook() Dim source As Workbook Dim destination As Workbook Set source = Workbooks("Source.xlsx") Set destination = Workbooks.Add source.Worksheets("Sheet1").Range("A1:D10").Copy Destination:=destination.Worksheets(1).Range("A1") End Sub

4
Run and save the result

With Source.xlsx open, run the macro from View > Macros > View Macros. In the new workbook, choose File > Save As to save the copied data.

Record and edit a macro to copy data into a new workbook
Use an existing destination instead: If the macro is stored in the destination workbook, replace Workbooks.Add with ThisWorkbook. Check the destination range before running the macro because the copy can overwrite existing cells.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. Its format compatibility helps you move existing spreadsheets into WPS; check macro behavior separately before relying on an Excel VBA workflow.

Copy spreadsheet data between open workbooksOpen and edit Microsoft Excel formats, including .xlsxUse a familiar spreadsheet interface for everyday tasksMove existing spreadsheet files into a lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can a recorded Excel macro work with more than one workbook?

Yes. Record the switches and copy actions, then use View > Macros > View Macros > Edit to check that the VBA references the intended source and destination workbooks.

Why does Workbooks("Source.xlsx") fail?

The named workbook must already be open, and its name must match exactly. Check the workbook name in Excel and update the Workbooks reference in the VBA editor.

How do I copy into the workbook that contains the macro?

In the VBA editor, set the destination to ThisWorkbook instead of Workbooks.Add. Specify the destination worksheet and cell in the Copy statement.

Can I paste sparklines as an image?

Yes. Use Range.CopyPicture on the cells containing the sparklines, then paste into the destination worksheet. The result is a static picture, not an editable sparkline.

Where should I save the macro?

When you start recording through View > Macros > Record Macro, choose a storage location. If you store it in a workbook, use File > Save As and select Excel Macro-Enabled Workbook (.xlsm).