简体   繁体   中英

Copy row value from sheet1 to sheet2 column

Sheet1.activate
Sheet1.range("C4:H4").select
selection.copy
Sheets("Sheet2").select
Range("C4:C9").pasteSpecial

This is the code I tried which does not work.

Try replacing the last 2 lines of code with the below. You will require the Transpose parameter.

Sheets("Sheet2").Range("C4:C9").PasteSpecial Paste:=xlPasteValues, Transpose:=True
Sheets("Sheet2").activate

first please avoid using Select Statements, try simply this

Sheets(1).Range("C4:H4").Copy
Sheets(2).Range("C4:H4").PasteSpecial 

its unnecessary to use select and Range.

If you simply copy then you also dont have to activate your Destination Sheet.

For further information see the documentation of the PasteSpecial Method: VBA PasteSpecial

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