ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select and copy a variable range (https://www.excelbanter.com/excel-programming/416307-select-copy-variable-range.html)

E. F.

Select and copy a variable range
 
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

Per Jessen[_2_]

Select and copy a variable range
 
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

On 29 Aug., 20:08, "E. F." wrote:
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



E. F.

Select and copy a variable range
 
Thank you for the prompt response.

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

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

On Aug 29, 2:36*pm, Per Jessen wrote:
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

On 29 Aug., 20:08, "E. F." wrote:



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- Hide quoted text -


- Show quoted text -



Dave Peterson

Select and copy a variable range
 
It is in xl97-xl2003.

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

xl2007 has 1MB rows.



"E. F." wrote:

Thank you for the prompt response.

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

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

On Aug 29, 2:36 pm, Per Jessen wrote:
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

On 29 Aug., 20:08, "E. F." wrote:



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- Hide quoted text -


- Show quoted text -


--

Dave Peterson

E. F.

Select and copy a variable range
 
Dave,

Thank you very much for the clarification.

Eugene
==============================================
On Aug 29, 6:05*pm, Dave Peterson wrote:
It is in xl97-xl2003.

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

xl2007 has 1MB rows.





"E. F." wrote:

Thank you for the prompt response.


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


TIA, Eugene



All times are GMT +1. The time now is 05:30 PM.

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