插入下一个空行

时间:2015-12-21 21:38:37

标签: excel vba excel-vba

我正在尝试在下一个可用行中插入数据,但它会丢失大量空白的行。

我的代码如下:

Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet

    Set copySheet = Worksheets("Recipe creater")
    Set pasteSheet = Worksheets("Recipes")

    Call Pasterecipedetails

    copySheet.Range("b6:g6", Range("b6:g6").End(xlDown)).Copy
    pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub



Sub Pasterecipedetails()

    Application.ScreenUpdating = False
    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet

    Set copySheet = Worksheets("Recipe creater")
    Set pasteSheet = Worksheets("Recipes")

    copySheet.Range("c2:e2").Copy
    pasteSheet.Cells(Rows.Count, 11).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True

End Sub

由于

1 个答案:

答案 0 :(得分:0)

尝试这样:

copySheet.UsedRange.Copy
nextRow = pasteSheet.UsedRange.SpecialCells(xlCellTypeLastCell).row + 1
pasteSheet.Cells(nextRow, 1).PasteSpecial (xlPasteValues)