vba剪切和过去的功能没有任何空白行

时间:2015-12-02 14:42:57

标签: excel-vba vba excel

请告知我下面的编码有什么问题。我能够切割并超过该行但在此之后我可以在我的工作表中看到空白行。我们如何自动调整行。

切割后,原始纸张上不应有任何空行。

Dim i As Variant
endrow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
For i = 2 To endrow
If ws1.Cells(i, "M").Value = str Then
ws1.Cells(i, "M").EntireRow.Cut Destination:=ws2.Range("A" & LastRow + ).EndxlUp).Offset(1)
End If
Next

1 个答案:

答案 0 :(得分:0)

这样可以解决问题:

Sub Test()
    Dim i As Long
    Dim endrow As Long

    'Added this code to get it working on my test file.
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim str As String
    Dim lastrow As Long
    Set ws1 = ThisWorkbook.Worksheets("Sheet1")
    Set ws2 = ThisWorkbook.Worksheets("Sheet2")
    str = "DELETE THIS ROW"
    lastrow = 30
    ''''''''''''''''''''''

    endrow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
    For i = endrow To 2 Step -1
    If ws1.Cells(i, "M").Value = str Then
        ws1.Cells(i, "M").EntireRow.Cut Destination:=ws2.Range("A" & lastrow).End(xlUp).Offset(1)
        ws1.Cells(i, "M").EntireRow.Delete Shift:=xlUp
    End If
    Next
End Sub