Use Excel VBA to Copy Data Through the Last Populated Row
Question details
The user wants an Excel VBA macro to copy a dataset between workbooks without hard-coding its final row or column.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro copies data from a source worksheet to a destination worksheet, starting below the headers.
- Observed behavior
- The existing macro uses a fixed range such as A2:G65000 rather than adapting to the populated dataset.
Open both workbooks in Excel and confirm their names, worksheet names, and the location of the source headers. The examples assume headers start at A1 and data should be pasted at A2 in the destination sheet.
Copy a Contiguous Dataset with CurrentRegion
Use CurrentRegion when the dataset around A1 has no completely blank separating rows or columns.
CurrentRegion expands to the surrounding block of cells. The macro skips the first row and reduces the copied range by one row so it does not include an extra row below the dataset.
In Excel, select Developer > Visual Basic, then choose Insert > Module.
Paste this code into the module, adjusting the workbook and sheet names if needed: Sub CopyCurrentRegionData() Dim sourceSheet As Worksheet Dim destinationSheet As Worksheet Dim dataRegion As Range Set sourceSheet = Workbooks("ClientData.xls").Sheets("ClientInfo") Set destinationSheet = Workbooks("ClientBio_v2.xlsm").Sheets("ClientInfo") Set dataRegion = sourceSheet.Range("A1").CurrentRegion If dataRegion.Rows.Count < 2 Then Exit Sub dataRegion.Offset(1, 0).Resize(dataRegion.Rows.Count - 1, dataRegion.Columns.Count).Copy _ Destination:=destinationSheet.Range("A2") End Sub
Return to Excel, select Developer > Macros, choose CopyCurrentRegionData, and select Run. Check the destination sheet starting at A2.

Find the Last Used Row and Column Before Copying
Use Find when the dataset can contain completely blank rows or columns, provided the source sheet has no unrelated content beyond the dataset.
Work with Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative for opening and editing spreadsheets in a familiar interface. Its Excel format support makes it easier to move existing files to WPS, although it does not repair Excel VBA macros and macro compatibility can vary.

Frequently Asked Questions
Why does CurrentRegion stop before the end of my data?
CurrentRegion stops at completely blank separating rows or columns. Remove the separators if appropriate, or use the Find-based macro to determine the last used row and column.
How can I copy the headers as well as the data?
In the CurrentRegion macro, replace the Offset and Resize copy statement with dataRegion.Copy Destination:=destinationSheet.Range("A1"). This copies the entire region, including its first row.
Do both workbooks need to be open?
Yes. These examples refer to open workbooks through the Workbooks collection. Open both files in Excel before running the macro, or add code to open them first.
Will the macro remove old rows from the destination sheet?
No. The copy overwrites the destination cells it reaches but leaves older data outside that range. Clear the relevant destination area first if those leftover cells are not needed.
Can WPS Office run the same VBA macro?
Macro support and compatibility can vary by WPS Office version and configuration. Test the macro in your installation before relying on it, especially when working with macro-enabled files.




