且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Excel宏剪切行并将其粘贴到另一个工作表

更新时间:2022-12-12 08:12:29

这是因为您尚未声明工作表.尝试以下代码:

It is because you haven't declared your sheets. Try the following code:

Sub MoveLS()
    Dim i As Variant
    Dim endrow As Integer
    Dim ASR As Worksheet, LS As Worksheet

    Set ASR = ActiveWorkbook.Sheets("ASR")
    Set LS = ActiveWorkbook.Sheets("LS")

    endrow = ASR.Range("A" & ASR.Rows.Count).End(xlUp).Row

    For i = 2 To endrow
        If ASR.Cells(i, "I").Value = "LS" Then
           ASR.Cells(i, "I").EntireRow.Cut Destination:=LS.Range("A" & LS.Rows.Count).End(xlUp).Offset(1)
        End If
    Next
End Sub