具有动态起点的循环

时间:2019-02-11 12:48:22

标签: loops dynamic skip

我正在尝试遍历列表,并在找到内容时使其跳过。但是它仍然循环遍历原始列表。我真的在尝试输出每个子装配的开始和结束行。在下面的代码中,我希望rw_srt用循环中找到的行进行更新,但是它不起作用。

Sub asdf()

Dim Arr4 As Variant
rw_srt = 8
rw_end0 = 763

    For Each cell In Range("B" & rw_srt & ":B" & rw_end0 - 1)
        If cell.Value = 5 And Range("I" & cell.Row).Value <> "" Then
            Arr4 = Split(cell.Value, ",")   'stores the starting row of the subassembly
            MsgBox cell.Row
            'find next level 4
            With Range("B" & cell.Row & ":B" & rw_end0 - 1)
                Set Rng = .Find(What:="4", After:=.Cells(.Cells.Count), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                If Not Rng Is Nothing Then
                    Application.Goto Rng, True 'value found
                    rw_srt = ActiveCell.Row
                    Arr4 = Split(cell.Value, ",")   'stores the ending row of the subassembly
                    MsgBox ActiveCell.Row
                End If
            End With


        End If
    Next cell

End Sub

0 个答案:

没有答案