简体   繁体   中英

How to select a range of cells in VBA?

I wrote a bunch of SAP scripting code that works great and here comes (as usual) one of those issues that make no sense whatsoever.

So, I've tried two lines of code so far and about 500 variations of those two. In both cases, I get "Application-defined or object-defined error."

ThisWorkbook.Worksheets(7).Range(Cells(3, 1) & Cells(3, 1).End(xlDown)).Copy
ThisWorkbook.Worksheets(7).Range("A3:" & Range("A3").End(xlDown)).Copy

I simply want to select from A3 all the way down as far as the data goes. Can it get any simpler than that?

The solution was to actually specify that the last row is the Address. Mind. Blown.

Range("A3:" & Range("A1048576").End(xlUp).Address).Copy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM