简体   繁体   English

如何将数据从范围复制到表中的最后一行(转置)?

[英]How to Copy Data from range to last row in table (transposed)?

Hello everyone I'm back for my second beginner VBA question (Same project as before)大家好,我回来回答我的第二个初学者 VBA 问题(与以前相同的项目)

Information: 2 Sheets - Database & Entry信息:2 张 - 数据库和条目

Both contain the same two tables just that Entry is transposed (headers in rows instead of columns)两者都包含相同的两个表,只是 Entry 被转置(行而不是列中的标题)

My goal is to copy the data from entry into the Databases' last row while adding an additional one.我的目标是将条目中的数据复制到数据库的最后一行,同时添加一个。 Ideally there would be a way to copy the formula's in data entry right over (or format the database columns to contain them)理想情况下,有一种方法可以直接复制数据输入中的公式(或格式化数据库列以包含它们)

The data is sorted and filtered in the database afterwards, hence the need for a table.之后在数据库中对数据进行排序和过滤,因此需要一个表。 I'm having real trouble with this entire ListObject thing and understanding how it works.我在整个 ListObject 的事情上遇到了真正的麻烦并理解它是如何工作的。

Returns run time error 1004: PasteSpecial method of range class failed on this line:在这一行返回运行时错误 1004:范围类的 PasteSpecial 方法失败:

tbl.Range(LastRow).PasteSpecial Paste:=xlValues, Transpose:=True

However if I change that line to:但是,如果我将该行更改为:
Sheets("Database").ListObjects("Entire").PasteSpecial Paste:=xlValues, Transpose:=True

i get a runtime 438 (object doesn't support this property or method) error, which i find very confusing cause they should be the same thing我收到运行时 438(对象不支持此属性或方法)错误,我觉得这很令人困惑,因为它们应该是同一件事

Thank you for any help or suggestions, they are greatly appreciated!感谢您的任何帮助或建议,非常感谢! Also slightly off-topic but if you know any good resource I could buy to improve feel free to let me know.也有点偏离主题,但如果您知道我可以购买的任何好的资源来改进,请随时告诉我。

  Private Sub CommandButton2_Click()

Dim Entry As Worksheet
  Set Entry = ActiveSheet

Dim tbl As ListObject
  Set tbl = Sheets("Database").ListObjects("Entire")

Dim LastRow As Integer
  LastRow = tbl.Range.Rows.Count

Application.ScreenUpdating = False
    If Entry.Range("E9") = "y" Then
        Entry.Range("E6:E100").Copy
        tbl.ListRows.Add AlwaysInsert:=True
        tbl.Range(LastRow).PasteSpecial Paste:=xlValues, Transpose:=True

        Entry.Columns("E").Delete
    Else
        Entry.Columns("E").Delete
    End If
Application.ScreenUpdating = True

End Sub

It's very easy to clear the clipboard in Excel accidentally, so you should (probably) always call .Copy immediately before .Paste/.PasteSpecial .这很容易不小心清除Excel中的剪贴板,所以你应该(可能)随时拨打.Copy之前.Paste/.PasteSpecial Changing the order of改变顺序

Entry.Range("E6:E100").Copy
tbl.ListRows.Add AlwaysInsert:=True

solves the problem.解决了这个问题。

暂无
暂无

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

相关问题 如何复制最后一行数据的范围并粘贴到它下面的行中 - How To Copy Range of Last Row of Data and Paste into Row below It 将范围从一个工作表复制到另一个工作表的最后一行数据 - Copy a Range From One Worksheet To The Last Row of Data On Another 如何将数据范围复制到另一个工作表的最后一行? - How to copy a data range to the last row on another worksheet? 将范围从一个表中的列复制到另一个表中的行,每次都添加到最后一行 - Copy a range from a column in one table to a row in another table, each time adding to last row 如何使用excel vba自动复制同一工作表中最后一行的数据并将其复制到同一表的最后一行? - How to copy the data in last row and copy to the last row of a table in the same worksheet automatically using excel vba? 如何将范围和过去复制到最后一行 - How to copy Range and past to last row 如何从Excel VBA中的另一个工作簿复制单元格范围直到最后一行 - How Do You Copy Range of Cells Until Last Row from Another Workbook in Excel VBA 如何在引用最后一行时复制一系列单元格 - How to copy a range of cells while referencing last row 在下一个空行的另一张纸上复制并粘贴(转置和值)设定范围 - Copy and Paste (transposed & values) a set range in a different sheet in the next empty row 如何复制一定范围的单元格,一次只能复制一个,并且总是复制到最后一行? - How to copy a range of cell but one at a time and always in the last row?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM