将数据从一个工作表附加到另一个Excel VBA

时间:2015-11-14 10:03:34

标签: excel-vba vba excel

我知道一点VBA,但是我遇到了问题,我正在尝试编写一个代码,将从1张表中复制所有数据,将其粘贴/粘贴到表2中的下一个空白单元格中,然后从中删除数据表1.我正在使用下面的代码,但我将单元格值替换为单词TRUE。

Sub Instal_Sum_Paste()

  ActiveWorkbook.Sheets("Vehicle working").Select

  Dim N As Long
  N = Cells(6, 2).End(xlDown).Row
  Set DT = Range("b6:G" & N)
  DT.Copy

  ActiveWorkbook.Sheets("Installation Summary").Select
  lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
  Range("B" & lMaxRows + 1).Select
  ActiveCell.Value = DT.PasteSpecial(xlPasteValues)

  ActiveWorkbook.Sheets("Vehicle working").Select
  DT.Select
  Selection.ClearContents

  MsgBox "done", vbOKOnly, "done"

End Sub

1 个答案:

答案 0 :(得分:0)

我设法找到了答案,我知道这很愚蠢:

 Sub Instal_Sum_Paste()

  ActiveWorkbook.Sheets("Vehicle working").Select

  Dim N As Long
  N = Cells(6, 2).End(xlDown).Row
  Set DT = Range("b6:G" & N)
  DT.Select
  Selection.Copy

  ActiveWorkbook.Sheets("Installation Summary").Select
  lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
  Range("B" & lMaxRows + 1).Select
  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone

  ActiveWorkbook.Sheets("Vehicle working").Select
  DT.Select
  Selection.ClearContents

  MsgBox "done", vbOKOnly, "done"

End Sub