Determine range with VBA

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?
 
T

Tom Ogilvy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top