首页 > 解决方案 > 将数据添加到另一个表

问题描述

我在一张表中有一个表(“table1”)。我有一个按钮,可以将表中的数据添加到另一张表中的另一个表中(“表”)。每次它覆盖数据。我想将数据(“table1”)添加到表(“table2”)而不是覆盖它。这是代码:

 Sheets("Letter (P V)").ListObjects("Table1").Range.Copy _
      Destination:=Sheets("Actual").Range("E2")

谢谢!

标签: excelvba

解决方案


我想你想要这样的东西

Dim ws As Worksheet
Dim rangeToPaste As Range
Set ws = Sheets("Actual")
'go up from the bottom to the first row populated in column 5(E) after do +1 to paste after the last row'
Set rangeToPaste = ws.Range("E" & ws.Cells(ws.rows.Count, 5).End(xlUp).row + 1)
Sheets("Letter (P V)").ListObjects("Table1").Range.Copy Destination:=rangeToPaste

推荐阅读