粘贴复制的东西在行的最后

我有一个表格填写东西,它的一个特定部分应该被复制到另一个表格的末尾。

With Sheets("Sheet1") If Application.WorksheetFunction.CountA(.Columns(2)) <> 0 Then lastrow = .Cells(rows.Count, "B").End(xlUp).Row Else lastrow = 1 End If .Cells(lastrow + 1, "B") = "my new value" End With 

我有这个代码find最后一行,并粘贴/写入“我的新价值”。 但是我需要它粘贴的不仅仅是一个单元格。 我只是需要它select那个写“我的新值”的部分。我应该可以做剩下的我现在使用下面的代码。 但它仍然从表格“Tabelle3”复制东西,但它应该复制表格“Tabelle2”

 Private Sub CommandButton1_Click() Dim lastRow As Long With Sheets("Tabelle3") If Application.WorksheetFunction.CountA(.Columns(1)) <> 0 Then lastRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1 '<~~ Add 1 here and not as you are doing Else lastRow = 1 End If Sheets("Tabelle2").Select Range("B85:S85").copy Sheets("Tabelle3").Select '~~> Paste special .Range("C" & lastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End With End Sub 

你必须find最后一个空行,然后简单地做一个粘贴或pastespecial如下所示。

 Sub Sample() Dim lastRow As Long With Sheets("Sheet1") If Application.WorksheetFunction.CountA(.Columns(2)) <> 0 Then lastRow = .Cells(Rows.Count, "B").End(xlUp).Row + 1 '<~~ Add 1 here and not as you are doing Else lastRow = 1 End If Range("Z10:Z100").Copy '~~> Paste special .Range("B" & lastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End With End Sub 

上面的代码将复制范围"Z10:Z100" ,并在B列中的下一个可用的行做一个pastespecial。如果你不想做一个pastespecial,并希望做一个直接粘贴,然后看到这个

 Sub Sample() Dim lastRow As Long With Sheets("Sheet1") If Application.WorksheetFunction.CountA(.Columns(2)) <> 0 Then lastRow = .Cells(Rows.Count, "B").End(xlUp).Row + 1 '<~~ Add 1 here and not as you are doing Else lastRow = 1 End If Range("Z10:Z100").Copy .Range("B" & lastRow) End With End Sub