Determine range with VBA

  • Thread starter Thread starter Bryon
  • Start date Start date
B

Bryon

I am looking to copy Data from another Workbook (which is
never the same size). what code do I need to determine
the last row that data is entered on so I can set up the
Range?
 
Dim rng as Range
with Workbooks("OtherName.xls").Worksheets("Sheet1")
set rng = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
set rng = rng.Resize(,10) ' to get 10 columns
End with

or

set rng = .Range("A1").CurrentRegion

or
' less reliable
set rng = .UsedRange
 
Back
Top