在excel vba中继续循环下一个循环

我在Excel VBA中有几个If语句的循环。 这通过并且隐藏某些行根据某一条件。 基本上,如果其中一个陈述是真的,那么该行是隐藏的。 由于只有一个陈述对于行被隐藏,所以只要其中一个陈述被发现是真实的,其余的陈述就被testing是没有意义的。 如果if语句被发现是真的,我将如何放置一行代码来说明循环的下一个迭代? 任何帮助将不胜感激!

 For i = 1 To rng2.Rows.Count If Left(rng3.Cells(i, 1).Value, 8) = "CMS Part" Then If rng3.Cells(i, 1).Value <> "CMS Part D (CY " & Year(Date) & ")" Then rng3.Cells(i, 1).EntireRow.Hidden = True End If End If If rng4.Cells(i, 1).Value = "Yes" Then rng4.Cells(i, 1).EntireRow.Hidden = True End If If InStr(1, CStr(rng5.Cells(i, 1).Value), "test") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "Test") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "demo") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "Demo") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "TEST") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "DO NOT USE") > 0 Then rng5.Cells(i, 1).EntireRow.Hidden = True End If Next i 

我知道使用goto语句通常是不好的编程,但是一个选项是:

 For i = 1 To rng2.Rows.Count If Left(rng3.Cells(i, 1).Value, 8) = "CMS Part" Then If rng3.Cells(i, 1).Value <> "CMS Part D (CY " & Year(Date) & ")" Then rng3.Cells(i, 1).EntireRow.Hidden = True Goto Skip End If End If If rng4.Cells(i, 1).Value = "Yes" Then rng4.Cells(i, 1).EntireRow.Hidden = True Goto Skip End If If InStr(1, CStr(rng5.Cells(i, 1).Value), "test") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "Test") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "demo") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "Demo") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "TEST") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "DO NOT USE") > 0 Then rng5.Cells(i, 1).EntireRow.Hidden = True Goto Skip End If Skip: Next i 

我知道其他人说,但这里是使用elseif的代码

 For i = 1 To rng2.Rows.Count If Left(rng3.Cells(i, 1).Value, 8) = "CMS Part" Then If rng3.Cells(i, 1).Value <> "CMS Part D (CY " & Year(Date) & ")" Then rng3.Cells(i, 1).EntireRow.Hidden = True End If ElseIf rng4.Cells(i, 1).Value = "Yes" Then rng4.Cells(i, 1).EntireRow.Hidden = True ElseIf InStr(1, CStr(rng5.Cells(i, 1).Value), "test") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "Test") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "demo") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "Demo") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "TEST") > 0 Or InStr(1, CStr(rng5.Cells(i, 1).Value), "DO NOT USE") > 0 Then rng5.Cells(i, 1).EntireRow.Hidden = True End If Next i