VBA复制和转置数据范围 [英] VBA Copy & Transpose Data Range
问题描述
我正在工作中设置一些电子表格以简化我的工作.我还是VBA的新手.
I am working on setuping a few spreadsheets at work to streamline my work. I'm still new to VBA.
我正在尝试从Sheet1的列(E6:E14)中剪切一定范围的数据并转置数据,然后再将数据粘贴到Sheet2的A列的下一个可用行中.到目前为止,这是我编写的代码,没有经过反复试验.每次我运行代码时,都会收到运行时错误"1004".我正在尝试在Sheet2中创建一个数据库".任何帮助都感激不尽.
I am trying to cut a range of data in a column (E6:E14) from Sheet1 and transposing the data before pasting the data in the next available row in Column A of Sheet2. Here is the code that I have written so far from trial and error. Everytime I run the code I get a Run-time error '1004'. I am trying to create a "database" in Sheet2. Any help is appreciate it.
Sub Test()
Worksheets("Sheet1").Range("E6:E14").Cut
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
End Sub
感谢您的帮助!
FHY
推荐答案
.Spec方法不适用于.Cut方法,但不适用于.Copy方法.当我更改
PasteSpecial is unavailable with the .Cut method, but not the .Copy method. When I changed
Worksheets("Sheet1").Range("E6:E14").Cut
到
Worksheets("Sheet1").Range("E6:E14").Copy
一切正常.如果您希望以后删除所有内容,则可以始终这样做:
everything worked fine. If you want everything deleted afterwards, you could always just do:
Sub Test()
Worksheets("Sheet1").Range("E6:E14").Copy
Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Transpose:=True
Worksheets("Sheet1").Range("E6:E14").Clear
End Sub
这篇关于VBA复制和转置数据范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!