I want a macro that will copy all rows in one sheet that have a certain name in them to a separate sheet.
My plan is to do it as a loop that stops when it can not find any more of the name. The problem is I can't figure out how to make the loop stop when the search fails when it has found all the occurrences.
Here is my code that loops 10 times. It works just fine except that I want to fix it so that it loops however many it takes and then stops. This could be anywhere from 0 times to 500 times.
By the way, the values I search for are in 3 different columns side by side.
I would really like to change the code as little as possible as I don't know VBA well and would like to avoid doing a lot of learning that I will be unlikely to use again.
    Dim Counter As Integer
    Range("A1").Select
    ' Start the loop that I want changed to stop automatically: 
    Do While Counter < 10
    Cells.Find(What:="matt johnson", After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Rows("1:1").EntireRow.Select
    Selection.Copy
    ' go to destination sheet:
    Sheets("Matt").Select
    ActiveCell.SpecialCells(xlLastCell).Select
    ActiveCell.Offset(1, 2).Range("A1").Select
    Selection.End(xlToLeft).Select
    ActiveSheet.Paste
    ' go back to source sheet:
    ActiveCell.Offset(1, 0).Range("A1").Select
    Sheets("Upcoming Deadlines").Select
    ActiveCell.Offset(0, 1).Range("A1").Select
    Selection.End(xlToRight).Select
    ActiveCell.Offset(0, 26).Range("A1").Select
    Application.CutCopyMode = False
    Counter = Counter + 1
    Loop
End Sub
 
     
    