[英]VBA Excel: How to assign range of cells to another range of cells?
New Excel VBA user here. 这里是新的Excel VBA用户。 I feel like I made a silly syntax mistake.
我觉得我犯了一个愚蠢的语法错误。
I am trying to copy some vertical cells in one worksheet, to horizontal cells in another worksheet. 我正在尝试将一个工作表中的一些垂直单元格复制到另一工作表中的水平单元格。
Worksheets("Master").Range("D14:F14").Value = Worksheets("Temp").Range("B12:B14").Value
However, the above command seems to only paste the value of B12 to cells D14:F14. 但是,以上命令似乎只将B12的值粘贴到单元格D14:F14中。 Is there a way to paste the cells of B12, B13, and B14 to D14:F14?
有没有办法将B12,B13和B14的单元格粘贴到D14:F14?
Use Application.Transpose() : 使用Application.Transpose() :
Worksheets("Master").Range("D14:F14").Value = Application.Transpose(Worksheets("Temp").Range("B12:B14").Value)
Or PasteSpecial : 或PasteSpecial :
Worksheets("Temp").Range("B12:B14").Copy
Worksheets("Master").Range("D14").PasteSpecial xlPasteAll, , , True
If you only want values then the first is best. 如果只需要值,则第一个为最佳。 When transposing with
PasteSpecial
one must use the xlPasteAll
. 与
PasteSpecial
转置时,必须使用xlPasteAll
。 It will throw an error if one tries to paste values only with transpose as true. 如果仅尝试使用转置为真粘贴值,则将引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.