Excel VBA - 退出循环 [英] Excel VBA - exit for loop

查看:820
本文介绍了Excel VBA - 退出循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当满足条件时,我想退出循环。当如果条件已满足时,我如何可以退出循环的我想我的如果语句结尾的某种退出,但不知道该如何工作。

I would like to exit my for loop when a condition inside is met. How could I exit my for loop when the if condition has been met? I think some kind of exit at the end of my if statement, but don't know how that would work.

Dim i As Long
For i = 1 To 50
    Range("B" & i).Select
    If Range("B" & i).Value = "Artikel" Then
        Dim temp As Long
        temp = i
    End If
Next i
Range("A1:Z" & temp - 1).EntireRow.Delete Shift:=xlToLeft


推荐答案

p>要提早退出你的循环,你可以使用 Exit For

To exit your loop early you can use Exit For

如果[condition]然后退出

这篇关于Excel VBA - 退出循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆