简体   繁体   中英

Copy range of cells from one sheet to another

I want to copy a column with a varying number of entries (by using .End(xlDown)) into column C of another sheet going downwards.

With Sheets("General Text")
    Range(Range("A2"), Range("A2").End(xlDown)).Copy 
    Destination:=Sheets("Compiler").Range(Range("C2"), Range("C2").End(xlDown))
End With

I'm not sure if this is the easiest method, but I've tried a few iterations and it always errors

First, using Copy with Destination is a 1-line command (not 2).

Second, you need to fully qualify your Range inside the With Sheets("General Text") statement, by addind a . as a prefix.

Try the code below:

With Sheets("General Text")
    .Range(.Range("A2"), .Range("A2").End(xlDown)).Copy Destination:=Sheets("Compiler").Range("C2")
End With

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