Modudes
Modudes

Reputation: 23

How to end this kind of do loop?

Good day,

I'm trying to end the loop I've done but not sure what should I enter. Once a value has been offset, that's it, I want to end the loop. Sometimes the value to find is more than one, and total of all data in the excel is until row 1500.

Please help me. Here's the code I've used below.

Sub third()

    Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A1500").End(xlUp))

    Do
        Set c = SrchRng.Find("31184", LookIn:=xlValues)
       If Not c Is Nothing Then c.Offset(0, 8).Value = "INPUT A NAME"
    Loop

End Sub

Upvotes: 1

Views: 37

Answers (1)

Gary's Student
Gary's Student

Reputation: 96781

How about:

Sub third()
    Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A1500").End(xlUp))
    Do
        Set c = SrchRng.Find("31184", LookIn:=xlValues)
        If Not c Is Nothing Then
            c.Offset(0, 8).Value = "INPUT A NAME"
            Exit Do
        End If
    Loop
End Sub

Upvotes: 2

Related Questions