宏编译错误 – 下一步不进行 for

宏编译错误 – 下一步不进行 for

我有一个宏,它有一个编译错误,我不知道如何修复它。它是倒数第二行“next”被突出显示,并且出现消息“Next without for”。我需要什么代码才能使这个宏工作?

Sub MOVEDOWN1()

Dim n, sht As Worksheet, cell As Range, num, tmp, rngDest As Range

    Set sht = ActiveSheet

    n = sht.Range("J2")

    For Each cell In sht.Range("P21:P52,U21:U52,Z21:Z52,AE21:AE52,AJ21:AJ52,AO21:AO52,AT21:AT52,AY21:AY52,BD21:BD52,BI21:BI52").Cells

        tmp = cell.Offset(0, 1).Value

        If cell.Value = n And tmp Like "*#-#*" Then

            'get the first number
            num = CLng(Trim(Split(tmp, "-")(0)))
            Debug.Print "Found a positive result in " & cell.Address

            'find the next empty cell in the appropriate row
         Set rngDest = sht.Cells(num, sht.Columns.Count).End(xlToLeft).Offset(0, 1)
            'make sure not to add before col L
            If rngDest.Column < 14 Then Set rngDest = sht.Cells(num, 14)

            cell.Offset(0, 1).Copy rngDest

              Rem Move the cell contents to the next cell

        tmp = cell.Offset(0, 1).Value

        If cell.Value = n And tmp Like "*#-#*" Then
         Cells(irow + 1, icol).Insert Shift:=xlDown
         Cells(irow, icol).Copy Cells(irow + 1, icol)
         Cells(irow, icol).Clear

            Exit For

        End If
    Next

End Sub

相关内容