Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do loop erroring

Status
Not open for further replies.

jacksmack

Technical User
Feb 26, 2005
3
US
I am a novice at writing macros and need what I hope is some easy to obtain advice. I am trying to create a maco that will search for some text and when it finds it will then delete the row where the text appears and then continue searching for the same text. I have a simple do loop that works, but I don't know how to make it stop when it doesn't find the text. It errors when it can't find the text.

Here is the code:

Do
Cells.Find(What:="Jackson Fish", LookAt:=xlWhole).Activate
Range(Selection, Selection.EntireRow).Select
Selection.Delete Shift:=xlUp
Loop

Thanks in advance
 



Hi,
Code:
    Dim rFound As Range
    Do
        Set rFound = Cells.Find(What:="Jackson Fish", LookAt:=xlWhole)
        If Not rFound Is Nothing Then
            Range(Selection, Selection.EntireRow).Delete Shift:=xlUp
        Else
            Exit Do
        End If
    Loop

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top