Excel VBA - exit for loop

0 votes

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

Mar 10 in Database by Edureka
• 13,640 points
38 views

1 answer to this question.

0 votes

When we need to depart the For Loop based on a set of criteria, we utilise the Exit For statement. The control goes to the next statement immediately after the For Loop when Exit For is invoked.

Syntax
Exit For Statement in VBA syntax is as follows.

Exit For
VBA Exit For statement
answered Mar 15 by gaurav
• 13,560 points

Related Questions In Database

0 votes
0 answers

How to loop in excel without VBA or macros?

Is it possible to iterate (loop) a ...READ MORE

Mar 30 in Database by Edureka
• 13,640 points
186 views
0 votes
1 answer

Syntax of for-loop in SQL Server

TSQL has no for-loop, we have only ...READ MORE

answered Feb 15 in Database by Neha
• 8,560 points
31 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23 in Database by gaurav
• 13,560 points
44 views
0 votes
1 answer

MS Excel - SumProduct formula with Loop

Drag this to the right of cell ...READ MORE

answered Mar 14 in Database by gaurav
• 13,560 points
28 views
0 votes
1 answer

[Excel][VBA] How to draw a line in a graph?

Sub MakeChart() Dim x(20) ...READ MORE

answered Mar 24 in Database by gaurav
• 13,560 points
77 views
0 votes
1 answer

Convert numbers to words in Excel (VBA)

In the cell where you wish to ...READ MORE

answered Mar 25 in Database by gaurav
• 13,560 points
82 views
0 votes
1 answer

How to use xlrd for writing an excel file

In Python, you can read and write ...READ MORE

answered Mar 30 in Database by gaurav
• 13,560 points
119 views
0 votes
1 answer

I have a Run Time Error 91 for an Excel Add In

"Runtime Error 91: Object variable or with ...READ MORE

answered Mar 30 in Database by gaurav
• 13,560 points
236 views
0 votes
1 answer

Excel vba for loop

You must understand how to use loops ...READ MORE

answered Apr 5 in Database by gaurav
• 13,560 points
70 views
0 votes
1 answer

#NAME? error in Excel for VBA Function

Because you have a module with the ...READ MORE

answered Apr 5 in Database by gaurav
• 13,560 points
53 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP