Select and copy a variable range

E

E. F.

In the following code is it possible to use the actual number of
filled-in rows instead of hard-coded maximum of 15,000?

Workbooks.Open FileName:=sDbf
Range("2:15000").Select
Selection.Copy
Destination:=ThisWorkbook.Sheets(sWSName).Range("2:15000")
ActiveWorkbook.Close

May be something with Rows.Count?

If it matters I'm working with Excel 2002.

TIA, Eugene
 
P

Per Jessen

Hi Eugene

I think this is what you need:

Workbooks.Open Filename:=sDbf
LastRow = Range("A65536").End(xlUp).Row
Rows("2:" & LastRow).Copy
Destination:=ThisWorkbook.Sheets(sWSName).Rows("2")
ActiveWorkbook.Close

Regards;
Per
 
E

E. F.

Thank you for the prompt response.

Is Range("A65536") equivalent to Range("A" & Rows.Count)?

TIA, Eugene
================================================================
 
D

Dave Peterson

It is in xl97-xl2003.

xl95 and previous had 16k rows (if I remember correctly).

xl2007 has 1MB rows.
 
E

E. F.

Dave,

Thank you very much for the clarification.

Eugene
==============================================
 
Top