简体   繁体   English

VBA 从表 1 复制列并将粘贴转置到表 2 中的行

[英]VBA copy column from sheet 1 and transpose paste into row in sheet 2

I am trying to write a macro to copy data from column C (to the last full row) and transpose paste that data into row 1 on sheet 2. I cannot get my code to work.我正在尝试编写一个宏来从 C 列复制数据(到最后一整行)并将该数据转置到工作表 2 上的第 1 行。我无法让我的代码工作。 I am getting a Run-time error 1004 for the Paste line of code.我收到粘贴代码行的运行时错误 1004。

Option Explicit
Sub ColumnRow()

    Dim lRow As Long

        lRow = Cells(Rows.Count, 1).End(xlUp).Row
        Worksheets("Sheet1").Range("C1" & lRow).Copy
        Worksheets("Sheet2").Range("A1").PasteSpecial Transpose:=True

End Sub

Couple of things.几件事。

(1) Specify the sheet for lRow (1) 为lRow指定工作表

(2) Syntax for range Range("C1" & lRow) was off - see below (2) 范围Range("C1" & lRow)的语法关闭 - 见下文

Sub ColumnRow()

Dim lRow As Long

lRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row 'add sheet ref
Worksheets("Sheet1").Range("C1:C" & lRow).Copy 'specify full range
Worksheets("Sheet2").Range("A1").PasteSpecial Transpose:=True

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制行,粘贴到其他工作表,然后将文本粘贴到列,然后转置 - Copy row, paste to different sheet, then text to column, then transpose VBA复制/粘贴值从上次使用的行的工作表1到工作表2? - VBA copy/paste value from sheet 1 to sheet 2 on last used row? Excel VBA如果第一行包含单词“结束日期”,则将工作表1的粘贴列复制到工作表2 - Excel VBA Copy Paste column from sheet 1 to sheet 2 if first row countain the word “End Date” 如何在VBA中复制整张纸并将其粘贴到另一张纸中? - How to copy a whole sheet and transpose paste into another sheet in VBA? VBA-从范围中搜索工作表名称。然后从范围表中复制,将转置粘贴到该工作表名称中 - VBA- search sheet name from range.. then copy from range sheet, paste transpose into that sheetname VBA从自动筛选器中复制并粘贴到另一张工作表中,输出一行 - VBA Copy and Paste in another Sheet from AutoFilter outputting one row 使用VBA中的应用程序工作表功能从一个工作表中复制列并粘贴为另一行中的行 - Copy a column from one sheet and paste as row in another using application worksheetfunciton match in vba 复制工作表的最后一行并粘贴到另一工作表的VBA的最后一行 - Copy last row of a sheet and paste in last row of a different sheet VBA Excel VBA - 如何复制和转置粘贴另一张纸 - Excel VBA - How do copy and transpose paste another sheet 从第二行复制一列数据,直到其中有数据的最后一行,然后粘贴为另一张表 VBA 上一列的最后一行 - Copy a column of data from the second row until the last row with data in it and paste as the last row in a column on another sheet VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM