Excel VBA - Change my For statement to ?

I need to change this "For" statement to something that when found true, then go on to do the next
For statement.


For b = 15 To 24
If Activesheet.Range("B" & b) <> "" Then
    Activesheet.Range("D" & b).Select
         Activesheet.Range("D" & b) = CommitNumber.TextBox1.Value '
End If
Next b


this is the code following:
'///////////////////////////////////////////////////////////////////////
For b = 15 To 24
If Activesheet.Range("B" & b) <> "" Then
    Activesheet.Range("D" & b).Select
         Activesheet.Range("D" & b) = CommitNumber.TextBox1.Value '
End If
Next b

For a = 16 To 24
Dim LastRow As Range
Set LastRow = Range("D24").End(xlUp)

If (Activesheet.Range("B" & a)) <> "" Then
    If (Activesheet.Range("D" & a)) = "" Then

    Activesheet.Range("D" & a) = LastRow + 1
    End If
Else
 
End If

Next a
ca1358Asked:
Who is Participating?
 
Wayne Taylor (webtubbs)Commented:
Oh, sorry, I misunderstood your question.

Use Exit For....

    For b = 15 To 24
        If Activesheet.Range("B" & b) <> "" Then
            Activesheet.Range("D" & b).Select
            Activesheet.Range("D" & b) = CommitNumber.TextBox1.Value
            Exit For
        End If
    Next b

Wayne
0
 
Wayne Taylor (webtubbs)Commented:
Hi ca1358,

There doesn't appear to be anything wrong with your For/Next loops. Using If/End If is the normal method for skipping an iteration, based on a condition.

Regards,

Wayne
0
 
ca1358Author Commented:
I need for this statement when it finds the first one to be true stop looping and go on to the next "For" Statement.

For b = 15 To 24
If Activesheet.Range("B" & b) <> "" Then
    Activesheet.Range("D" & b).Select
         Activesheet.Range("D" & b) = CommitNumber.TextBox1.Value '
End If
Next b
0
 
ca1358Author Commented:
Thank you!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.