ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determine range with VBA (https://www.excelbanter.com/excel-programming/280585-determine-range-vba.html)

Bryon[_2_]

Determine range with VBA
 
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?

Tom Ogilvy

Determine range with VBA
 
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

--
Regards,
Tom Ogilvy

Bryon wrote in message
...
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?





All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com