如果符合条件,则将行移动到另一张表

时间:2015-12-30 18:11:31

标签: excel vba excel-vba copy paste

如果单元格等于迪士尼奥兰多,我想转到工作表New或全新的工作表。截至目前,.Rows正在导致错误。

Sub finddisneys()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim wb As Workbook
Dim ws As Worksheet


Set wb = ActiveWorkbook
Set ws1 = wb.Sheets("April")
Set ws2 = wb.Sheets("alljobs")
Set ws3 = wb.Sheets("New")


i = ws1.Cells(Rows.Count, 2).End(xlUp).Row
For i = z To 2 Step -1
    If ws1.Cells(i, 2) = "Disney Orlando" Then
        .Rows(i).Copy Destination:=ws3.range("A")
    End If

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

1 个答案:

答案 0 :(得分:2)

只需要在代码上做一些“管家”:

Sub finddisneys()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim wb As Workbook
Dim ws As Worksheet


Set wb = ActiveWorkbook
Set ws1 = wb.Sheets("April")
Set ws2 = wb.Sheets("alljobs")
Set WS3 = wb.Sheets("New")


i = ws1.Cells(ws1.Rows.Count, 2).End(xlUp).row ' Added ws1 before "Rows" for clarity
For i = z To 2 Step -1
    If ws1.Cells(i, 2) = "Disney Orlando" Then
        ws1.Rows(i).copy Destination:=WS3.Range("A") ' Added ws1, since you didn't have `With` anywhere.
    End If
Next i ' Need this to continue the loop

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

编辑:啊,我看到Scott和Jeeped都到处都是。