1

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
Community
  • 1
  • 1
Modudes
  • 23
  • 1
  • 2
  • 7
  • 2
    use `If Not c Is Nothing Then c.Offset(0, 8).Value = "INPUT A NAME": Exit Do` – Dmitry Pavliv May 31 '14 at 13:57
  • So, even if there's more than one "31184" you just want to deal with the first one found? Or do you want to process all of them? If it's the first thing, then Gary's Student has an answer that works. If the second [this SO answer](http://stackoverflow.com/a/10988232/293078) should help. – Doug Glancy May 31 '14 at 14:14
  • Do you need to find and set value for all matches? – L42 May 31 '14 at 14:17
  • Thanks for the link Doug! I'll review that and see what I can incorporate on my code. – Modudes May 31 '14 at 14:25

1 Answers1

2

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
Gary's Student
  • 95,722
  • 10
  • 59
  • 99