Help with Selection.Find (novice with Visual Basic Editor)

Hello all,

I am currently modifying a macro (I fool around with VBE but really have only 2 classes of Java under my belt) with the code below:

Cells.Select
Selection.Find(What:="<Current>", After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
        False).Activate

My problem is, I have no idea how to handle the error when the string is not found.  Instead, if the String is not in the worksheet, it breaks the code.

If anyone can let me know how to syntactically throw an error, I'd appreciate it!

Thanks,
     Kevin



Answer this question

Help with Selection.Find (novice with Visual Basic Editor)

  • Avesta

    This example finds all cells in the range A1:A500 on worksheet one that contain the value 2 and changes it to 5.



    With Worksheets(1).Range("a1:a500")
        Set c = .Find(2, lookin:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                c.Value = 5
                Set c = .class
    ="bterm">FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With



     


    You can always use the On Error clause in VBA to catch your errors













  • Help with Selection.Find (novice with Visual Basic Editor)