How to Copy Data from Unknown Range with VBA

How to copy data from an unknown range in another workbook using the UsedRange property with VBA. We have learnt to copy data from one workbook to another and from one workbook to another in a specific worksheet. All the time we knew the exact range of the data to be copied. Let’s learn how to copy the data from an unknown range in a workbook sheet. Watch the video below:

Watch this video on YouTube.

Here’s the complete VBA code:

Sub myUsedRange()
Workbooks.Open Filename:=”C:\Users\takyar\copyData\copyPastefromUsedRange.xlsx”
ActiveSheet.UsedRange.Offset(1, 0).Copy
ActiveWorkbook.Close Save = False

erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

ActiveSheet.Cells(erow, 1).Select
‘Application.CutCopyMode = False

End Sub

Data in unknown range
Data in unknown range

Further Reading:

Worksheet UsedRange Property